#include <algorithm>
using namespace std;
constexpr int mask(int x) { return x + (x >> 10); }
constexpr int kN = 1e7;
int h[kN], p[kN];
int f[mask(kN) + 1];
void add(int n, int x) {
for (++x; x <= n; x += x & -x) {
++f[mask(x)];
}
}
int sum(int x) {
int s = 0;
for (; x; x &= x - 1) {
s += f[mask(x)];
}
return s;
}
void count_2d(int n, const unsigned *x, const unsigned *y, unsigned *out) {
fill_n(h, n, -1);
for (int i = 0; i < n; ++i) {
p[i] = h[x[i]];
h[x[i]] = i;
}
for (int i = 0; i < n; ++i) {
for (int j = h[i]; ~j; j = p[j]) {
out[j] = sum(y[j]);
}
for (int j = h[i]; ~j; j = p[j]) {
add(n, y[j]);
}
}
}