eolymp
bolt
Try our new interface for solving problems
Problems

Hoof, Paper, Scissors (Gold)

Hoof, Paper, Scissors (Gold)

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". Bessie, being an expert at the game, can predict each of FJ'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. 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 FJ will be playing, please determine the maximum number of games that Bessie can win.

Input

The first line contains n (1n105) and k (0k20). The remaining n lines contains FJ'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.

Time limit 1 second
Memory limit 128 MiB
Input example #1
5 1
P
P
H
P
S
Output example #1
4
Source 2017 USACO January, Gold