#include #include #include #define repeat(i,n) for (int i = 0; (i) < (n); ++(i)) using namespace std; template void setmax(T & a, T const & b) { if (a < b) a = b; } int main() { int kr, kb; string s; cin >> kr >> kb >> s; deque stk; int ans = 0; function go = [&](int i) { if (stk.size() + s.length() - i <= ans) { return 0; } int acc = 0; if (i == s.length()) { setmax(acc, stk.size()); } else { if (s[i] == 'R') { if (kr-1 >= stk.size() or stk[kr-1] != 'R') { stk.push_front('R'); setmax(acc, go(i+1)); stk.pop_front(); } setmax(acc, go(i+1)); } else if (s[i] == 'B') { if (kb-1 >= stk.size() or stk[kb-1] != 'B') { stk.push_front('B'); setmax(acc, go(i+1)); stk.pop_front(); } setmax(acc, go(i+1)); } else { stk.push_front('W'); setmax(acc, go(i+1)); stk.pop_front(); } } setmax(ans, acc); return acc; }; go(0); cout << ans << endl; return 0; }