Count Inversions
An inversion is a pair with . Count them. is too slow for large — count while doing merge sort.
Input
, then integers.
Output
The number of inversions.
Constraints
— the answer can need 64 bits.
Sample 1
Input
5 2 4 1 3 5
Output
3
Sample 2
Input
5 5 4 3 2 1
Output
10