#include #include using namespace std; int people[100010] = { 0 }; int counter = 0; void quickSort(int start, int end) { if (start >= end) return; int pivot = people[(end - start) / 2]; for (int l = start, r = end; l < r; ) { if (people[l] < people[pivot]) { l++; continue; } if (people[r] > people[pivot]) { r--; continue; } counter++; swap(people[l], people[r]); } quickSort(start, pivot - 1); quickSort(pivot + 1, end); } int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &people[i]); } quickSort(0, n-1); printf("%d\n", counter); }