Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/saralash-inversiyalar

Number of inversions

Medium 1000 ms 128 MB 53%
Share

$n$ integers $a_{1}, a_{2}, \ldots, a_{n}$ are given. How many pairs (inversions) are there with $i \lt j$ and $a_{i} \gt a_{j}$?

Array cells; each out-of-order pair is joined by an arc, and their count is shown

Input

The first line contains a positive integer $n$. The second line contains $n$ integers $a_{i}$ separated by spaces.

Output

One integer — the number of inversions.

Note

$1 \le n \le 10^{5}$
$-10^{9} \le a_{i} \le 10^{9}$

Examples

Input #1
5
2 4 1 3 5
Output #1
3
Input #2
1
10
Output #2
0

Sign in to submit a solution

Signing up is free and takes a minute.