#include #include #include #include #include #include using namespace std; const int N = 30; int kr, kb; string s; int check(int bits) { string str(60, '?'); int nw = 0; int nrb = 0; for (int i = 0; i < N; i++) { if (s[i] == 'W') { str[nw + nrb] = 'W'; nw++; } else if ((bits >> (i - nw)) & 1) { str[nw + nrb] = s[i]; nrb++; } } int len = nw + nrb; for (int i = 0; i < len; i++) { if ((str[i] == 'B' && str[i + kb] == 'B') || (str[i] == 'R' && str[i + kr] == 'R')) { return -1; } } return len; } int main() { cin >> kr >> kb >> s; int limit = 1 << 20; int ans = -1; for (int i = 0; i < limit; i++) { ans = max(ans, check(i)); } cout << ans << endl; return 0; }