static int n;
static int k;
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine().trim(), " ");
n = Integer.parseInt(st.nextToken());
k = Integer.parseInt(st.nextToken());
char[] line = br.readLine().toCharArray();
int peopleNum = 0;
for (int i = 0; i < n; i++) {
if (line[i] == 'P' && isAteHamburger(i, line)) {
peopleNum++;
}
}
System.out.println(peopleNum);
}
private static boolean isAteHamburger(int index, char[] line) {
int start = Math.max(0, index - k);
int end = Math.min(n - 1, index + k);
for (int i = start; i <= end; i++) {
if (line[i] == 'H') {
line[i] = 'T';
return true;
}
}
return false;
}
출처:https://www.acmicpc.net/problem/19941