#include #include #include #include #include #include #include #include using namespace std; int Kr,Kb; string S; vectorSP; int mx; int dfs(string word) { if (word.size() <= mx)return 0; else if (find(SP.begin(), SP.end(), word) != SP.end())return 0; else SP.push_back(word); set s; queue que; for (int i = 0; i < word.size(); i++) { if (i + Kr < word.size() && word[i] == 'R'&&word[i + Kr] == 'R') { for (int j = i; j <= i + Kr; j++) { if (word[j] != 'W') s.insert(j); } } else if (i + Kb < word.size() && word[i] == 'B'&&word[i + Kb] == 'B') { for (int j = i; j <= i + Kb; j++) { if (word[j] != 'W') s.insert(j); } } } if (s.size() == 0) return max(mx, (int)word.size()); for (auto itr = s.begin(); itr != s.end(); itr++) { que.push(*itr); //cout << *itr << endl; } //cout << word << endl; while (que.size()) { //cout << st.size() << endl; string word2 = word; int p = que.front(); que.pop(); //cout << p << endl; word2.erase(word2.begin() + p); mx = max(mx, dfs(word2)); //cout << word2 << endl; //cout << mx << endl; } return mx; } int main() { cin >> Kr >> Kb; cin >> S; cout << dfs(S) << endl; return 0; }