EasyRating 900
Line Up for Photos
Soldiers stand in a row. The tallest must be first and the shortest last. Each second, two neighbours can swap. Print the fewest seconds needed. If several are tallest, use the leftmost; if several are shortest, use the rightmost.
Input
n, then n heights.
Output
The number of swaps.
Sample 1
Input
4 33 44 11 22
Output
2
Sample 2
Input
7 10 10 58 31 63 40 76
Output
10
Output appears here