int n; int arr[MAXSIZE]; int temp[MAXSIZE]; longlong ans = 0;
voidmerge_sort(int from, int mid, int to) { int i = from; int j = mid+1; int index = from;
while (i <= mid && j <= to) { if (arr[i] <= arr[j]) temp[index++] = arr[i++]; else { temp[index++] = arr[j++]; ans = ans + j-index; } }
if (i > mid) { for (int l = j; l <= to; l++) temp[index++] = arr[l]; } else { for (int l = i; l <= mid; l++) { temp[index++] = arr[l]; } } for (int l = from; l <= to; l++) { arr[l] = temp[l]; } }