#ds103. 逆序对2

逆序对2

Inversion Pairs 2

Problem Description

You are given nn numbers a1,a2,…,ana_1, a_2, \dots, a_n. For two numbers x,yx, y in the array, if xx appears before yy and x>yx > y, then (x,y)(x, y) is called an inversion pair of the array aa. How many inversion pairs are there 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

Output one number on a single line, the answer.

Sample Input

4
4 2 3 1

Sample Output

5

Sample Explanation

The 5 inversion pairs are (4,2),(4,3),(4,1),(2,1),(3,1)(4,2), (4,3), (4,1), (2,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.