Problem

2 /7


Bubble sort: number of exchanges

Problem

Determine how many exchanges the ascending bubble sort algorithm will do for the given array.
 
Input
The first line is a number (\(1 <= N <= 1000\)) – the number of elements in the array. On the second line – the array itself. It is guaranteed that all array elements are different and do not exceed 109.
 
Output
Print a single number – number of bubble sort exchanges.
 
Examples
# Input Output
1
5
1 2 3 4 5 
0
2
5
5 4 3 2 1
10