#include #include using namespace std; int kr, kb; string s; bool is_valid(char block, string blocks) { int len = blocks.size(); if (block == 'W') { return true; } else if (block == 'R' && (len - kr < 0 || blocks[len - kr] != 'R')) { return true; } else if (block == 'B' && (len - kb < 0 || blocks[len - kb] != 'B')) { return true; } else { return false; } } int dfs(int idx, int max_len, string blocks) { if (idx == s.size()) { return max(max_len, static_cast(blocks.size())); } if (s.size() - idx + blocks.size() < max_len) { return max_len; } auto res = max_len; auto block = s[idx]; // ひっこぬかないパターン if (is_valid(block, blocks)) { res = max(res, dfs(idx + 1, res, blocks + block)); } // ひっこぬくパターン res = max(res, dfs(idx + 1, res, blocks)); return res; } int main() { cin >> kr >> kb >> s; cout << dfs(0, 0, "") << endl; return 0; }