#CCBCHBAHAI0000164. Tướng quân đến duyệt đội (Arrival of the General)
Tướng quân đến duyệt đội (Arrival of the General)
Arrival of the General
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem
soldiers stand in a line with heights . The line is accepted when a maximum-height soldier is first and a minimum-height soldier is last. In one second, two adjacent soldiers may swap.
Find the minimum number of adjacent swaps required. With ties, moving the leftmost maximum to the front and the rightmost minimum to the back is optimal.
Input
- Line 1: integer .
- Line 2: heights.
Output
Print the minimum number of seconds.
Subtask
Subtask 1 (100 points): ; .
Example
Input
4
33 44 11 22
Output
2
Explanation
Move one position left and one position right: two adjacent swaps in total.