Problems
We want to perform an insertion sort on a sequence
For example, if the array 20, 40, 30, 10, the insertion sort proceeds as follows:
i = 1 →
20, 40, 30, 10| movements: 0i = 2 →
20, 40, 30, 10| movements: 0i = 3 →
20, 30, 40, 10| movements: 1 (40 moves to make space for 30)i = 4 →
10, 20, 30, 40| movements: 3 (20, 30, 40 move to make space for 10)
The total number of movements for the insertion sort to complete is 4.
Input
The first line contains an integer
The second line contains
Output
Print a single integer representing the total number of element movements that occur during the insertion sort.
Example #1
4
20 40 30 10
4
Example #2
3
-1 1 0
1
Tag
Source
JUNGOL