#c22601. 逆序对2

逆序对2

Inversion Pairs (II)

Problem Description

Given nn numbers a1,a2,…,ana_1, a_2, \dots, a_n. For two numbers x,yx, y, if xx appears before yy and xx is greater than yy, then (x,y)(x, y) is called an inversion pair of the array aa. How many inversion pairs does array aa have in total? Formally, count the number of pairs (i,j)(i, j) such that i<ji < j and ai>aja_i > a_j.

Input Format

The first line contains an integer nn.

The next line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n.

Output Format

One line with one number, the answer.

Sample Input

4
4 2 3 1

Sample Output

5

Sample Explanation

The 5 inversion pairs are (4,2)(4,2), (4,3)(4,3), (4,1)(4,1), (2,1)(2,1), (3,1)(3,1).

Constraints

For 100%100\% of the data: 2≤n≤1000002 \leq n \leq 100000, 1≤ai≤n1 \leq a_i \leq n, and each number appears exactly once.