#include #include #include #include #include #include #include #include #include using namespace std; //namaega184 int main(){ int r,b;char s[101];scanf("%d%d%s",&r,&b,s); set st;st.insert(string(s)); auto cmparetor=[](string &a,string &b){return a.size(),decltype(cmparetor)> pq(cmparetor);pq.push(string(s)); int change=1; int ans=0; auto ischange=[&](string str,int pos,int npos){ str.erase(str.begin()+pos+npos); //printf("%s\n",str.c_str()); if(st.find(str)==st.end()){ pq.push(str);st.insert(str); } return 1; }; while(change){ change = 0; string tmp; for(int i=0;i=0&&tmp[j-r]=='R')change|=ischange(tmp,j,-r); } else if(tmp[j]=='B'){ if(j+b=0&&tmp[j-b]=='B')change|=ischange(tmp,j,-b); } } if(change==0)break; } ans=tmp.size(); } printf("%d\n",ans); return 0; }