How many inversions? P80595


Statement
 

pdf   zip

Count the number of inversions of every given sequence of nn integer numbers x1xnx_1 \dots x_n. Remember that an inversion is a pair of indices ii and jj such that 1i<jn1 \le i < j \le n and xi>xjx_i > x_j.

Input

Input consists of several cases, each one with nn followed by the nn integer numbers x1xnx_1 \dots x_n. Assume 0n500000 \le n \le 50000.

Output

For every case, print the number of inversions of the sequence.

Public test cases
  • Input

    4   2 3 5 7
    4   7 5 3 2
    3   -7 -7 -7
    

    Output

    0
    6
    0
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Official solutions
    C++ Python
    User solutions
    C++ Python