#include #include #include #include #include #include #include #include #include // require sort next_permutation count __gcd reverse etc. #include // require abs exit atof atoi #include // require scanf printf #include #include // require accumulate #include // require fabs #include #include #include #include // require setw #include // require stringstream #include // require memset #include // require tolower, toupper #include // require freopen #include // require srand #define rep(i,n) for(int i=0;i<(n);i++) #define ALL(A) A.begin(), A.end() using namespace std; typedef long long ll; typedef pair P; typedef pair CI; int solve (string s, int G, int C, int P ){ int res = 0; rep (i, s.length() ){ if (s[i] == 'C' ){ if (G > 0 ){ res += 3; G--; }else if (C > 0 ){ res += 1; C--; }else{ P--; } // end if }else if (s[i] == 'G' ){ if (P > 0 ){ res += 3; P--; }else if (G > 0 ){ res += 1; G--; }else{ C--; } // end if }else{ // if (s[i] == 'P' ) if (C > 0 ){ res += 3; C--; }else if (P > 0 ){ res += 1; P--; }else{ G--; } // end if } // end if } // end rep return res; } bool cmp (CI a, CI b ){ return a.second <= b.second; } int main() { ios_base::sync_with_stdio(0); int G, C, P; cin >> G >> C >> P; string s; cin >> s; set g; rep (i, s.length() ) g.insert (s[i] ); set::iterator it = g.begin(); string order = ""; for (; it != g.end(); it++ ){ order += (*it); } // end for int res = 0; do{ map rank_hand; rank_hand.clear(); rep (i, order.length() ) rank_hand[order[i]] = i; vector curr; curr.clear(); rep (i, s.length() ){ char t = s[i]; int r = rank_hand[s[i]]; curr.push_back (CI (t, r ) ); } // end rep if (order.length() != 1 ) sort (ALL (curr ), cmp ); string u = ""; rep (i, s.length() ) u += curr[i].first; cerr << u << endl; int cur = solve (u, G, C, P ); res = max (res, cur ); }while (next_permutation(ALL (order ) ) ); cout << res << endl; return 0; }