#t266. 求逆序对

求逆序对

Counting Inversions

Problem Background

Special for beginners, ^_^

Problem Description

Given a sequence a1,a2,…,ana_1, a_2, \dots, a_n, if there exist i<ji < j and ai>aja_i > a_j, we call it an inversion pair. Find the number of inversion pairs in aa.

Input Format

The first line is nn, the length of the sequence. The next nn lines follow, where line i+1i + 1 gives the ii-th number in the sequence.

Output Format

The number of inversion pairs in aa.

Sample Input

4
3
2
3
2

Sample Output

3

Constraints

1s, 1024KiB for each test case.

N≤105N \le 10^5, Ai≤105A_i \le 10^5.