Skip to content
UPEEC

Count Inversions

Hard#sorting#merge-sort#divide-and-conquer· solved by 0 · time limit 2.0 s

An inversion is a pair i<ji < j with ai>aja_i > a_j. Count them. O(n2)O(n^2) is too slow for large nn — count while doing merge sort.

Input

nn, then nn integers.

Output

The number of inversions.

Constraints

1≤n≤2×1051 \le n \le 2 \times 10^5 — 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

Sign in or join free to run and submit your solution.