An Inversion Problem

View as PDF

Submit solution

Points: 10
Time limit: 2.0s
Memory limit: 64M

Author:
Problem type

Given a permutation of the integers 1 to N, print out the number of inversions in the array.

An inversion is defined as a pair of indices, i, j such that i \neq j, i < j, a_i > a_j.

Input Specification

The first line will contain the integer N (1 \le N \le 10^5).

The second line will contain N integers, a_1, a_2, \ldots a_N (1 \le a_i \le N).

It is guaranteed the second line will contain a valid permutation of the integers from 1 to N.

Output Specification

Output the number of inversions in the permutation.

Sample Input

4
3 2 1 4

Sample Output

3

Comments

There are no comments at the moment.