One Time Swap

AtCoder
IDabc345_c
Time2000ms
Memory256MB
Difficulty
You are given a string $S$. Find the number of strings that can result from performing the following operation **exactly once**. * Let $N$ be the length of $S$. Choose a pair of integers $(i,j)$ such that $1\leq i<j\leq N$ and swap the $i$\-th and $j$\-th characters of $S$. It can be proved that you can always perform it under the constraints of this problem. ## Constraints * $S$ is a string of length between $2$ and $10^6$, inclusive, consisting of lowercase English letters. ## Input The input is given from Standard Input in the following format: $S$ [samples]
Samples
Input #1
abc
Output #1
3

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

*   Swapping the $1$\-st and $2$\-nd characters of $S$ results in $S$ being `bac`.
*   Swapping the $1$\-st and $3$\-rd characters of $S$ results in $S$ being `cba`.
*   Swapping the $2$\-nd and $3$\-rd characters of $S$ results in $S$ being `acb`.

Therefore, the operation on `abc` results in one of the three strings: `bac`, `cba`, and `acb`, so print $3$.
Input #2
aaaaa
Output #2
1

Swapping any two characters results in $S$ remaining `aaaaa`. Thus, only one string can result from the operation.
API Response (JSON)
{
  "problem": {
    "name": "One Time Swap",
    "description": {
      "content": "You are given a string $S$. Find the number of strings that can result from performing the following operation **exactly once**. *   Let $N$ be the length of $S$. Choose a pair of integers $(i,j)$ su",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc345_c"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given a string $S$. Find the number of strings that can result from performing the following operation **exactly once**.\n\n*   Let $N$ be the length of $S$. Choose a pair of integers $(i,j)$ su...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments