#K14916. Counting Inversions
Counting Inversions
Counting Inversions
Given a sequence of integers, your task is to compute the number of inversions in the sequence.
An inversion is defined as a pair of indices \( (i, j) \) such that \( i a_j \). The number of inversions in the sequence gives a measure of how far the sequence is from being sorted.
For example, for the sequence [5, 3, 2, 4, 1], there are 8 inversions.
inputFormat
The input is given via standard input. The first line contains an integer \( n \) representing the number of elements in the sequence. The second line contains \( n \) space-separated integers representing the sequence.
outputFormat
Output a single integer representing the number of inversions in the given sequence. The output should be printed to standard output.
## sample5
5 3 2 4 1
8
</p>