

実行時間制限: 2 sec / メモリ制限: 256 MB
配点 : 点
問題文
からなる順列 が与えられます。 次の操作を何回か (回でもよい) 行うことが出来ます。
操作: 順列で隣り合う二つの数を選んでスワップする。
何回か操作を行って、任意の に対して となるようにしたいです。 必要な操作の最小回数を求めてください。
制約
- は の順列である。
入力
入力は以下の形式で標準入力から与えられる。
..
出力
必要な操作の最小回数を出力せよ。
入力例 1Copy
5 1 4 3 5 2
出力例 1Copy
2
と を入れ替え、その後 と を入れ替えることで は となり、これは条件を満たします。 これが最小回数なので、答えは となります。
入力例 2Copy
2 1 2
出力例 2Copy
1
と を入れ替えれば条件を満たします。
入力例 3Copy
2 2 1
出力例 3Copy
0
初めから条件を満たしています。
入力例 4Copy
9 1 2 4 9 5 8 7 3 6
出力例 4Copy
3
Score : points
Problem Statement
You are given a permutation consisting of ,,..,. You can perform the following operation any number of times (possibly zero):
Operation: Swap two adjacent elements in the permutation.
You want to have for all . Find the minimum required number of operations to achieve this.
Constraints
- is a permutation of .
Input
The input is given from Standard Input in the following format:
..
Output
Print the minimum required number of operations
Sample Input 1Copy
5 1 4 3 5 2
Sample Output 1Copy
2
Swap and , then swap and . is now and satisfies the condition. This is the minimum possible number, so the answer is .
Sample Input 2Copy
2 1 2
Sample Output 2Copy
1
Swapping and satisfies the condition.
Sample Input 3Copy
2 2 1
Sample Output 3Copy
0
The condition is already satisfied initially.
Sample Input 4Copy
9 1 2 4 9 5 8 7 3 6
Sample Output 4Copy
3