import std.algorithm, std.array, std.container, std.range, std.bitmanip; import std.numeric, std.math, std.bigint, std.random, core.bitop; import std.string, std.conv, std.stdio, std.typecons; void main() { auto rd = readln.split.map!(to!int); auto kr = rd[0], kb = rd[1]; auto s = readln.chomp; int[string] memo; bool calc(string t) { foreach (i, c; t) { switch (c) { case 'R': if (i < t.length - kr && t[i + kr] == 'R') return false; break; case 'B': if (i < t.length - kb && t[i + kb] == 'B') return false; break; default: } } return true; } int dp(string t) { if (t in memo) return memo[t]; if (calc(t)) { memo[t] = t.length.to!int; return t.length.to!int; } auto maxLen = 0; foreach (i, c; t) { if (c != 'W') { auto r = dp(t[0..i] ~ t[i + 1..$]); maxLen = max(maxLen, r); } } memo[t] = maxLen; return maxLen; } writeln(dp(s)); }