cswork / OA打开练习工作台

AmazonOA #219

Get Minimum Number of Moves (A.K.A. Weight Lifting Equipments:)

估计简单可在线判题

考点(AI 标注)原地数组

Blocks of distinct weights are arranged in an array, and each operation swaps two adjacent blocks. The lightest block must end up first and the heaviest last; the middle does not need to be sorted. Find the minimum number of swaps.

输入格式

The first line contains n; the second line contains the distinct weights. 2≤n≤100000, 1≤weight≤10^9.

输出格式

Output a single integer, the answer.

样例 1

输入:

5
2 4 3 1 6

输出:

3

样例 2

输入:

3
3 2 1

输出:

3

样例 3

输入:

3
1 3 2

输出:

1

样例说明

The answers are 3, 3 and 1. In the second example the two extremes cross, and that step must not be counted twice.