// Header {{{ // includes {{{ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // }}} using namespace std; // consts {{{ static const int INF = 1e9; static const double PI = acos(-1.0); static const double EPS = 1e-10; // }}} // typedefs {{{ typedef long long int LL; typedef unsigned long long int ULL; typedef vector VI; typedef vector VVI; typedef vector VLL; typedef vector VVLL; typedef vector VULL; typedef vector VVULL; typedef vector VD; typedef vector VVD; typedef vector VB; typedef vector VVB; typedef vector VC; typedef vector VVC; typedef vector VS; typedef vector VVS; typedef pair PII; typedef complex P; // }}} // macros & inline functions {{{ // syntax sugars {{{ #define FOR(i, b, e) for (int i = (b); i < (e); ++i) #define FORI(i, b, e) for (int i = (b); i <= (e); ++i) #define RFOR(i, b, e) for (int i = (b); i > (e); --i) #define RFORI(i, b, e) for (int i = (b); i >= (e); --i) #define REP(i, n) FOR(i, 0, n) #define REPI(i, n) FORI(i, 0, n) #define RREP(i, n) RFOR(i, n, 0) #define RREPI(i, n) RFORI(i, n, 0) #define OPOVER(_op, _type) inline bool operator _op (const _type &t) const // }}} // conversion {{{ inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } // }}} // array and STL {{{ #define ARRSIZE(a) ( sizeof(a) / sizeof(a[0]) ) #define F first #define S second #define MP(a, b) make_pair(a, b) #define PB(e) push_back(e) #define SORT(v) sort((v).begin(), (v).end()) #define RSORT(v) sort((v).rbegin(), (v).rend()) #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define EXIST(s, e) ((s).find(e) != (s).end()) // }}} // for readable code {{{ #define EVEN(n) (n % 2 == 0) #define ODD(n) (!EVEN(n)) // }}} // string manipulation {{{ inline VS split(string s, char delimiter) { VS v; string t; REP(i, s.length()) { if (s[i] == delimiter) v.PB(t), t = ""; else t += s[i]; } v.PB(t); return v; } inline string join(VS s, string j) { string t; REP(i, s.size()) { t += s[i] + j; } return t; } // }}} // geometry {{{ #define Y real() #define X imag() // }}} // 2 dimentional array {{{ P dydx4[4] = { P(-1, 0), P(0, 1), P(1, 0), P(0, -1) }; P dydx8[8] = { P(-1, 0), P(0, 1), P(1, 0), P(0, -1), P(-1, 1), P(1, 1), P(1, -1), P(-1, -1) }; int g_height, g_width; bool in_field(P p) { return (0 <= p.Y && p.Y < g_height) && (0 <= p.X && p.X < g_width); } // }}} // }}} #define PRINT(s) sout << (s) << endl int main(int argc, char** argv) { cin.tie(0); ios::sync_with_stdio(false); ostringstream sout; int g1, c1, p1; cin >> g1 >> c1 >> p1; string s; cin >> s; int g2(0), c2(0), p2(0); for(auto c: s){ switch(c){ case 'G': g2++; break; case 'C': c2++; break; case 'P': p2++; break; default: break; } } //cout << g2 << c2 << p2 << endl; int score(0); if(g2 - p1 >= 0){ g2 -= p1; score += p1 * 3; p1 = 0; }else{ p1 -= g2; score += g2 * 3; g2 = 0; } if(c2 - g1 >= 0){ c2 -= g1; score += g1 * 3; g1 = 0; }else{ g1 -= c2; score += c2 * 3; c2 = 0; } if(p2 - c1 >= 0){ p2 -= c1; score += c1 * 3; c1 = 0; }else{ c1 -= p2; score += p2 * 3; p2 = 0; } if(g1 != 0 && g2 != 0){ score += (g1 < g2 ? g1 : g2); } if(c1 != 0 && c2 != 0){ score += (c1 < c2 ? c1 : c2); } if(p1 != 0 && p2 != 0){ score += (p1 < p2 ? p1 : p2); } cout << score << endl; return 0; }