#abc264d. D - "redocta".swap(i,i+1)

D - "redocta".swap(i,i+1)

Score : 400400 points

问题描述

你将获得一个字符串 SS,它是 atcoder 的一个排列。

在该字符串 SS 上,你需要执行以下操作零次或多次:

  • 选择 SS 中的两个相邻字符并交换它们。

找出使 SS 等于 atcoder 所需的最少操作次数。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

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

  • Choose two adjacent characters of SS and swap them.

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

Constraints

  • SS is a string that is a permutation of atcoder

Input

Input is given from Standard Input in the following format:

SS

Output

Print the answer as an integer.

Sample Input 1

catredo

Sample Output 1

8

You can make SS equal atcoder in 88 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 SS is already atcoder.

Sample Input 3

redocta

Sample Output 3

21

update @ 2024/3/10 11:09:23