#T256. 求逆序对

求逆序对

Description

Given a sequence a1,a2,,ana_1, a_2, \dots, a_n, if there exists i<ji < j and ai>aja_i > a_j, then this pair is called an inversion. The task is to count the total number of inversions in the sequence.

Input Format

The first line contains nn, representing the length of the sequence. The following nn lines each contain one element of the sequence, where the (i+1)(i+1)-th line corresponds to the ii-th element of the sequence.

Output Format

The total number of inversions in the sequence.

4
3
2
3
2

3

Hint

N105,Ai105N \leq 10^5, A_i \leq 10^5.