

Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 点
問題文
atcoder
の並べ替えである文字列 が与えられます。
この文字列 に対して以下の操作を 回以上行います。
- 中の隣接する 文字を選び、入れ替える。
を atcoder
にするために必要な最小の操作回数を求めてください。
制約
- は
atcoder
の並べ替えである文字列
入力
入力は以下の形式で標準入力から与えられる。
出力
答えを整数として出力せよ。
入力例 1Copy
catredo
出力例 1Copy
8
catredo
[ac]tredo
actre[od]
actr[oe]d
actro[de]
act[or]de
acto[dr]e
a[tc]odre
atcod[er]
という流れで操作を行うと、 回で を atcoder
にすることができ、これが達成可能な最小の操作回数です。
入力例 2Copy
atcoder
出力例 2Copy
0
この場合、文字列 は元から atcoder
です。
入力例 3Copy
redocta
出力例 3Copy
21
Score : points
Problem Statement
You are given a string that is a permutation of atcoder
.
On this string , you will perform the following operation or more times:
- Choose two adjacent characters of and swap them.
Find the minimum number of operations required to make equal atcoder
.
Constraints
- is a string that is a permutation of
atcoder
Input
Input is given from Standard Input in the following format:
Output
Print the answer as an integer.
Sample Input 1Copy
catredo
Sample Output 1Copy
8
You can make equal atcoder
in operations as follows:
catredo
[ac]tredo
actre[od]
actr[oe]d
actro[de]
act[or]de
acto[dr]e
a[tc]odre
atcod[er]
This is the minimum number of operations achievable.
Sample Input 2Copy
atcoder
Sample Output 2Copy
0
In this case, the string is already atcoder
.
Sample Input 3Copy
redocta
Sample Output 3Copy
21