QOJ.ac

QOJ

حد الوقت: 1 s حد الذاكرة: 1024 MB مجموع النقاط: 100 قابلة للهجوم ✓

#18287. KSA String 3

الإحصائيات

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, selecting one of the two each time:

  • Remove two adjacent characters from the string.
  • Add two identical characters to the beginning of the string.

By performing appropriate operations on the given string $X$, we want to change $X$ into a string that the KSAAC staff like with the same length as $X$. Find the minimum number of operations required.

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 that the KSAAC staff like with the same length as $X$.

It is guaranteed that by performing the given operations a finite number of times, the given string $X$ can be changed into a string that the KSAAC staff like with the same length as $X$.

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 90 No additional constraints

Examples

Input 1

KSKA

Output 1

8

Input 2

KKK

Output 2

6

Note

In Example 1, the goal is to change the given string to KSAK.

Adding KK, SS, AA, KK makes the string KKSSAAKKKSKA. Deleting the $2$nd, $6$th, $9$th, and $11$th characters, along with the characters to their right, yields the KSAK.

In Example 2, the goal is to change the given string to KSA.

Adding KK, SS, AA makes the string KKSSAAKKK. Deleting the $2$nd, $6$th, and $8$th characters, along with the characters to their right, yields the KSA.

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.