#abc345c. C - One Time Swap

C - One Time Swap

Points: 350350 points

问题陈述

给定一个字符串 SS。找出通过执行以下操作恰好一次可以得到的字符串数量。

  • NNSS 的长度。选择一对整数 (i,j)(i,j),使得 1i<jN1\leq i<j\leq N 并交换 SS 中的第 ii 个和第 jj 个字符。

可以证明,在这个问题的约束条件下,你总是可以执行这个操作。

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

You are given a string SS. Find the number of strings that can result from performing the following operation exactly once.

  • Let NN be the length of SS. Choose a pair of integers (i,j)(i,j) such that 1i<jN1\leq i<j\leq N and swap the ii-th and jj-th characters of SS.

It can be proved that you can always perform it under the constraints of this problem.

Constraints

  • SS is a string of length between 22 and 10610^6, inclusive, consisting of lowercase English letters.

Input

The input is given from Standard Input in the following format:

SS

Output

Print the number of strings that can result from performing the operation in the problem statement exactly once on SS.

Sample Input 1

abc

Sample Output 1

3

The length of SS is 33, so 1i<j31\leq i<j\leq 3 is satisfied by three pairs of integers (i,j)(i,j): (1,2)(1,2), (1,3)(1,3), and (2,3)(2,3).

  • Swapping the 11-st and 22-nd characters of SS results in SS being bac.
  • Swapping the 11-st and 33-rd characters of SS results in SS being cba.
  • Swapping the 22-nd and 33-rd characters of SS results in SS being acb.

Therefore, the operation on abc results in one of the three strings: bac, cba, and acb, so print 33.

Sample Input 2

aaaaa

Sample Output 2

1

Swapping any two characters results in SS remaining aaaaa. Thus, only one string can result from the operation.

update @ 2024/5/16 17:16:45

}