PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#QHD0000030. Móng, giấy, kéo (Hoof, Paper, Scissors)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Móng, giấy, kéo (Hoof, Paper, Scissors)

Hoof, Paper, Scissors

Source: USACO

Version: Phuoc Hung OJ Extended

Problem Statement

Bessie plays NN games of Hoof, Paper, Scissors and knows all the opponent’s moves in advance.

In each game, Bessie chooses H (hoof), P (paper), or S (scissors). H beats S, S beats P, and P beats H. Bessie may keep a gesture for several games, but may change gestures between consecutive games at most KK times.

Find the maximum number of games Bessie can win.

Input

The first line contains NN and KK.

Each of the next NN lines contains one of H, P, or S, the opponent’s gesture in that game.

Output

Print the maximum number of games Bessie can win.

Subtasks

  • Subtask 1 (20 points): 1≤N≤151\le N\le 15; 0≤K≤200\le K\le 20; Each input gesture is one of H, P, S.
  • Subtask 2 (30 points): 1≤N≤10001\le N\le 1000; 0≤K≤200\le K\le 20; Each input gesture is one of H, P, S.
  • Subtask 3 (50 points): 1≤N≤1051\le N\le 10^5; 0≤K≤200\le K\le 20; Each input gesture is one of H, P, S.

Examples

Input

5 1
P
P
H
P
S

Output

4

Explanation

The opponent plays P, P, H, P, S. Bessie can use S in the first four games, then switch to H for the last game. Bessie wins games 11, 22, 44, and 55: four wins with only one gesture change.