## Description

You have probably heard of the game “Rock, Paper, Scissors”. The cows like to play a similar game they call “Hoof, Paper, Scissors”.

The rules of “Hoof, Paper, Scissors” are simple. Two cows play against each-other. They both count to three and then each simultaneously makes a gesture that represents either a hoof, a piece of paper, or a pair of scissors. Hoof beats scissors (since a hoof can smash a pair of scissors), scissors beats paper (since scissors can cut paper), and paper beats hoof (since the hoof can get a papercut). For example, if the first cow makes a “hoof” gesture and the second a “paper” gesture, then the second cow wins. Of course, it is also possible to tie, if both cows make the same gesture.

Farmer John wants to play against his prize cow, Bessie, at $$n$$ games of “Hoof, Paper, Scissors”$$(1 \leq n \leq 100000)$$. Bessie, being an expert at the game, can predict each of Farmer John ‘s gestures before he makes it. Unfortunately, Bessie, being a cow, is also very lazy. As a result, she tends to play the same gesture multiple times in a row. In fact, she is only willing to switch gestures at most $$k$$ times over the entire set of games $$(0 \leq k \leq 20)$$. For example, if $$k = 2$$, she might play “hoof” for the first few games, then switch to “paper” for a while, then finish the remaining games playing “hoof”.

Given the sequence of gestures Farmer John will be playing, please determine the maximum number of games that Bessie can win.

## Input

The first line of the input file contains $$n$$ and $$k$$.

The remaining $$n$$ lines contains Farmer John’ s gestures, each either H,P, or S.

## Output

Print the maximum number of games Bessie can win, given that she can only change gestures at most $$k$$ times.

## Sample Input

5 1
P
P
H
P
S

## Sample Output

4

## Explanation

$$dp(i, j, k)$$ 表示已经出到第 $$i$$ 次, 已经换了 $$j$$ 次, 当前出的是 $$k$$.

## Source Code


#include <iostream>
#include <cstdlib>
#include <cstdio>

#define rep(_var,_begin,_end) for(int _var=_begin;_var<=_end;_var++)
#define range(_begin,_end) rep(_,_begin,_end)
#define maximize(__x,__y) __x=max(__x,__y)
using namespace std;
typedef long long lli;
const int maxn = 100100, maxm = 30;
#define HOOF 0
#define SCISSORS 1
#define PAPER 2

const int match = { // match[Bessie][FJ]
{ 0, 1, 0 },
{ 0, 0, 1 },
{ 1, 0, 0 } };
int n, K;
int arr[maxn];
int dp[maxn][maxm];

int main(int argc, char** argv)
{
scanf("%d%d", &n, &K);
for (int i = 1; i <= n; i++) {
static char str;
scanf("%s", str);
switch (str) {
case 'H': arr[i] = HOOF; break;
case 'S': arr[i] = SCISSORS; break;
case 'P': arr[i] = PAPER; break;
default: break;
}
}
// Ere a great dump of complicated reading.
// Reset the initial states of dp[][][].
range(0, 2) dp[_] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= K; j++) {
for (int k = 0; k <= 2; k++) {
dp[i][j][k] = dp[i - 1][j][k];
if (j > 0) range(0, 2) if (_ != k)
maximize(dp[i][j][k], dp[i - 1][j - 1][_]);
dp[i][j][k] += match[k][arr[i]];
}
}
}
// Retrieve result
int res = 0;
for (int j = 0; j <= K; j++)
for (int k = 0; k <= 2; k++)
maximize(res, dp[n][j][k]);
printf("%d\n", res);
return 0;
}