#include <algorithm>
int part(unsigned *a, int n){
int mid = a[n/2], i = -1, j = n;
while (true)
{
do ++i; while (a[i] < mid);
do --j; while (a[j] > mid);
if (i >= j) return i;
std::swap(a[i], a[j]);
}
}
void sort(unsigned *a, int n) {
if (n <= 1)
return;
int p = part(a, n);
sort(a, p);
sort(a + p, n - p);
}