const int N = 10000000;
int head[N];
int next[N];
int tree[N];
void count_2d(int n, const unsigned int * x, const unsigned int * y, unsigned int * out) {
for (int i = 0; i < n; ++i) {
head[i] = -1;
}
for (int i = 0; i < n; ++i) {
next[i] = head[x[i]];
head[x[i]] = i;
}
for (int i = 0; i < n; ++i) {
for (int j = head[i]; j >= 0; j = next[j]) {
int answer;
answer = 0;
for (int k = y[j]; k > 0; k = k - (k & -k)) {
answer = answer + tree[k];
}
out[j] = answer;
}
for (int j = head[i]; j >= 0; j = next[j]) {
for (int k = y[j] + 1; k < n; k = k + (k & -k)) {
tree[k] = tree[k] + 1;
}
}
}
}