#include <algorithm>
const int ful = (1 << (1 << 4)) - 1;
int tt[ful + 5];
void sort(unsigned *a, int n) {
unsigned *tmp = new unsigned[n + 1];
for (register int C = 0; C <= 1; C++) {
for (register int i = 0; i <= ful; i++) tt[i] = 0;
for (register int i = 0; i < n; i++) ++tt[(a[i] >> (C << 4)) & ful];
for (register int i = 1; i <= ful; i++) tt[i] += tt[i - 1];
for (register int i = n - 1; ~i; i--) tmp[--tt[(a[i] >> (C << 4)) & ful]] = a[i];
swap(a, tmp);
}
}