#include <iostream> #include <vector> #include <cmath> #include <map> #include <set> #include <iomanip> #include <queue> #include <algorithm> #include <numeric> #include <deque> #include <complex> using namespace std; int r, b; bool check(string &T){ for (int i=0; i<30; i++){ if (T[i] == 'R'){ if ((i-r >= 0 && T[i-r] == 'R') || (i+r < T.size() && T[i+r] == 'R')) return 0; } else if (T[i] == 'B'){ if ((i-b >= 0 && T[i-b] == 'B') || (i+b < T.size() && T[i+b] == 'B')) return 0; } } return 1; } int main(){ int cnt, mx=0; string S, T; cin >> r >> b >> S; for (int i=(1<<20)-1; i>=0; i--){ T = ""; cnt = 0; for (int j=0; j<20; j++){ while (j+cnt < 30 && S[j+cnt] == 'W'){ T += 'W'; cnt++; } if (i & (1<<j)) T += S[j+cnt]; } while (20+cnt < 30 && S[20+cnt] == 'W'){ T += 'W'; cnt++; } if (check(T)) mx = max(mx, (int)T.size()); } cout << mx << endl; return 0; }