408641: GYM103241 P Abc's (Hard Version)

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

P. Abc's (Hard Version)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

For a second time, Elijah is playing against a computer in a game called 'ABCs', where each side takes turns playing the letter $$$A$$$, $$$B$$$, or $$$C$$$, with the computer going first. Every time Elijah plays a letter, he gets a point if and only if it is a card that the computer has played the most of up until that point (ties included). For example if the computer has played $$$AABC$$$, Elijah will only get a point if he plays $$$A$$$, but if the computer has played $$$ACBBC$$$ then Elijah will get a point whether he plays a $$$B$$$ or a $$$C$$$.

Being the trickster that he is, Elijah hacked into the game and found out the exact order the computer will play the letters. Unfortunately for him, the game found out about this trickery, and this time decided to punish him by only allowing him switch letters after playing the same letter at least $$$K$$$ consecutive times. Elijah wants to make the best of the situation, and wants to compute to maximum possible of points he can achieve.

Input

The first line contains $$$N (1 \leq N \leq 10^5)$$$, denoting the number of turns, and $$$K (1 \leq K \leq N)$$$. The next line contains a string with $$$N$$$ characters describing what letters the computer will play in the game (as obtained by Elijah's nefarious hacking).

Output

Output the maximum points that Elijah can achieve if he is only allowed to switch letters after playing the same letter at least $$$K$$$ consecutive times.

ExampleInput
9 3
ABBCCCBAB
Output
8
Note

If Elijah plays $$$BBBBCCCBB$$$, he gets a point on every turn except the first one.

Problem idea: Bossologist/PurpleCrayon

Problem preparation: Bossologist

Occurances: Novice 15, Intermediate 10, Advanced 5

加入题单

算法标签: