#include using namespace std; #define DUMP(x) cerr << #x << "=" << x << endl #define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("< >(x) #define rep(i,n) for(int i=0;i<(int)(n);i++) #define REP(i,m,n) for (int i=m;i<(int)(n);i++) #define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h)) #define ALL(a) (a).begin(),(a).end() typedef long long ll; const int INF = 1e9; const ll INFLL = 1e18; typedef pair PII; int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1}; int Kr, Kb; bool check(string S) { int N = S.size(); rep(i, N) { if (S[i] != 'W') { int K = (S[i] == 'R' ? Kr : Kb); if (i - K >= 0 && S[i] == S[i - K]) return false; if (i + K < N && S[i] == S[i + K]) return false; } } return true; } int main() { ios::sync_with_stdio(false); cin >> Kr >> Kb; string S; cin >> S; int ans = 0; for (int i=0; i<(1<<20); i++) { int cnt = 0; string tmp; for (auto s : S) { if (s == 'W') { tmp += s; } else { if (i>>cnt&1) tmp += s; cnt++; } } if (check(tmp)) ans = max(ans, (int)tmp.size()); } cout << ans << endl; }