Codeforces Round 596 (Div. 1, based on Technocup 2020 Elimination Round 2)
F
Cursor Distance
Codeforces
3500
原题
← E→
翻译中…

There is a string $s$ of lowercase English letters. A cursor is positioned on one of the characters. The cursor can be moved with the following operation: choose a letter $c$ and a direction (left or right). The cursor is then moved to the closest occurence of $c$ in the chosen direction. If there is no letter $c$ in that direction, the cursor stays in place. For example, if $s = \mathtt{abaab}$ with the cursor on the second character ($\mathtt{a[b]aab}$), then:

翻译中…
  • moving to the closest letter $\mathtt{a}$ to the left places the cursor on the first character ($\mathtt{[a]baab}$);
  • moving to the closest letter $\mathtt{a}$ to the right places the cursor the third character ($\mathtt{ab[a]ab}$);
  • moving to the closest letter $\mathtt{b}$ to the right places the cursor on the fifth character ($\mathtt{abaa[b]}$);
  • any other operation leaves the cursor in place.
翻译中…

Let $\mathrm{dist}(i, j)$ be the smallest number of operations needed to move the cursor from the $i$-th character to the $j$-th character. Compute $\displaystyle \sum_{i = 1}^n \sum_{j = 1}^n \mathrm{dist}(i, j)$.

翻译中…

Input

翻译中…

The only line contains a non-empty string $s$ of at most $10^5$ lowercase English letters.

翻译中…

Output

翻译中…

Print a single integer $\displaystyle \sum_{i = 1}^n \sum_{j = 1}^n \mathrm{dist}(i, j)$.

翻译中…

Note

翻译中…

In the first sample case, $\mathrm{dist}(i, j) = 0$ for any pair $i = j$, and $1$ for all other pairs.

翻译中…

样例

Input #1
abcde
Output #1
20
InputCopy OutputCopy
Input #2
abacaba
Output #2
58
InputCopy OutputCopy
题目信息
题号
1246F
时间限制
2 s
内存限制
512 MB

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。