Universal Cup Judging System

Universal Cup

Límite de tiempo: 1 s Límite de memoria: 1024 MB Puntuación total: 100 Hackeable ✓
Estadísticas

Because the KSAAC staff love KSA, they like strings that satisfy the following conditions.

When the length of the string is $N$, for all $i$ such that $1\leq i\leq N$

  • If the remainder after dividing $i$ by $3$ is $1$, the $i$-th character is K.
  • If the remainder after dividing $i$ by $3$ is $2$, the $i$-th character is S.
  • If the remainder after dividing $i$ by $3$ is $0$, the $i$-th character is A.

The following operations can be performed $0$ or more times on the string.

  • Remove one character from the string.
  • Add one character at the beginning of the string.
  • Add one character at the end of the string.

By performing operations on the given string $X$, we try to change $X$ into a string of the same length as $X$, which the KSAAC staff like. Find the minimum number of operations required for it.

Input

The first line contains a string $X$.

Output

Print the minimum number of operations needed to change the given string $X$ into a string of the same length as $X$, which the KSAAC staff like.

Constraints

  • $1\le |X|\le 5\times 10^5$
  • $X_i \in \{$ K , S , A $\}$

Scoring

No. Points Constraints
$1$ $10$ All characters in string $X$ are identical
$2$ $30$ $ X \geq 3$; String $X$ starts with KSA
$3$ $60$ No additional constraints

Examples

Input 1

KKSKASKA

Output 1

8

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.