102643: [AtCoder]ABC264 D - "redocta".swap(i,i+1)

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $400$ points

Problem Statement

You are given a string $S$ that is a permutation of atcoder.
On this string $S$, you will perform the following operation $0$ or more times:

  • Choose two adjacent characters of $S$ and swap them.

Find the minimum number of operations required to make $S$ equal atcoder.

Constraints

  • $S$ is a string that is a permutation of atcoder

Input

Input is given from Standard Input in the following format:

$S$

Output

Print the answer as an integer.


Sample Input 1

catredo

Sample Output 1

8

You can make $S$ equal atcoder in $8$ operations as follows:
catredo $\rightarrow$ [ac]tredo $\rightarrow$ actre[od] $\rightarrow$ actr[oe]d $\rightarrow$ actro[de] $\rightarrow$ act[or]de $\rightarrow$ acto[dr]e $\rightarrow$ a[tc]odre $\rightarrow$ atcod[er]
This is the minimum number of operations achievable.


Sample Input 2

atcoder

Sample Output 2

0

In this case, the string $S$ is already atcoder.


Sample Input 3

redocta

Sample Output 3

21

Input

题意翻译

给定一个字符串,包含 $\tt a,t,c,o,d,e,r$ 各一个。每一次操作可以将相邻的两个字符交换,问最少多少次操作可以将该字符串变为 $\tt atcoder$。

Output

分数:400分

问题描述

你将得到一个字符串$S$,它是atcoder的排列。

  • 在字符串$S$上执行以下操作0次或多次:

选择$S$的两个相邻字符并交换它们。

找出使$S$等于atcoder所需的最小操作次数。

约束

  • $S$是一个字符串,它是atcoder的排列

输入

输入标准输入,格式如下:

$S$

输出

将答案作为整数打印。


样例输入 1

catredo

样例输出 1

8

你可以通过以下8次操作使$S$等于atcoder
catredo $\rightarrow$ [ac]tredo $\rightarrow$ actre[od] $\rightarrow$ actr[oe]d $\rightarrow$ actro[de] $\rightarrow$ act[or]de $\rightarrow$ acto[dr]e $\rightarrow$ a[tc]odre $\rightarrow$ atcod[er]
这是可实现的最小操作次数。


样例输入 2

atcoder

样例输出 2

0

在这种情况下,字符串$S$已经是atcoder


样例输入 3

redocta

样例输出 3

21

加入题单

算法标签: