#include #include #include using namespace std; int Kr, Kb; string S; bool check(const string& str) { for (int i = 0; i < str.length(); i++) { if (str[i] == 'R' && i + Kr < str.length() && str[i + Kr] == 'R') { return false; } if (str[i] == 'B' && i + Kb < str.length() && str[i + Kb] == 'B') { return false; } } return true; } int main() { cin >> Kr >> Kb >> S; int s = 0; for (int i = 0; i < S.length(); i++) { if (S[i] != 'W') { s |= (1 << i); } } int res = 0; int comb = s; do { string str; for (int i = 0; i < S.length(); i++) { if (((comb >> i) & 1) == 0) { str += S[i]; } } if (check(str)) { res = max(res, (int)str.length()); } comb = (comb - 1) & s; } while (comb != s); cout << res << endl; return 0; }