CSES - KILO 2017 5/5 - Mega Inversions
  • Time limit: 3.00 s
  • Memory limit: 512 MB

The n^2 upper bound for any sorting algorithm is easy to obtain: just take two elements that are misplaced with respect to each other and swap them. Uolevi conceived an algorithm that proceeds by taking not two, but three misplaced elements. That is, take three elements a_i > a_j > a_k with i < j < k and place them in order a_k, a_j , a_i . Now if for the original algorithm the steps are bounded by the maximum number of inversions \frac{n(n−1)}{2}, Uolevi is at his wits' end as to the upper bound for such triples in a given sequence. He asks you to write a program that counts the number of such triples.

Input

The first line of the input is the length of the sequence, n. The next line contains the integer sequence a_1, a_2, \ldots, a_n.

Output

Output the number of inverted triples.

Constraints

  • 1 \le n \le 5 \cdot 10^5
  • 1 \le a_i \le n

Examples

Input:

3
1 2 3

Output:

0

Input:

4
3 3 2 1

Output:

2