#pragma region template #pragma GCC optimize("Ofast") #include using i8 = std::int8_t;using i16 = std::int16_t;using i32 = std::int32_t;using i64 = std::int64_t;using u8 = std::uint8_t;using u16 = std::uint16_t;using u32 = std::uint32_t;using u64 = std::uint64_t;using f32 = float;using f64 = double;using vi32 = std::vector;using vu32 = std::vector;using vi64 = std::vector;using vu64 = std::vector;using vvi32 = std::vector;using vvu32 = std::vector;using vvi64 = std::vector;using vvu64 = std::vector;using pi32 = std::pair;using pi64 = std::pair; #define FOR(i,a,b) for(i64 i=(a), i##_len=(b); i(n); ++i) #define RFOR(i,a,b) for(i64 i=(a), i##_len=(b); i>i##_len; --i) #define RFORS(i,n) RFOR(i,n,0) #define ALL(obj) (obj).begin(),(obj).end() #define CLR(ar,val) memset(ar, val, sizeof(ar)) #define SZ(obj) (static_cast(obj.size())) #define cauto const auto& #define pb push_back #define mp make_pair const i32 dx[4]={1,0,-1,0}; const i32 dy[4]={0,1,0,-1}; const i32 INF32 = 0x3F3F3F3F; const i64 INF64 = 0x3F3F3F3F3F3F3F3F; const i64 MOD = 1000000007; template inline bool chmax(T &a, const T &b) { if (a inline bool chmin(T &a, const T &b) { if (b std::istream &operator>>(std::istream &is, std::pair &p) { is >> p.first >> p.second;return is; } template std::ostream &operator<<(std::ostream &os, const std::pair& p) { os << p.first << ' ' << p.second;return os; } template std::istream &operator>>(std::istream &is, std::vector &v) { for(T& in : v) is >> in; return is; } template std::ostream &operator<<(std::ostream &os, const std::vector &v) { for(i32 i = 0; i < SZ(v); i++) os << v[i] << (i+1 != SZ(v) ? " " : ""); return os; } // input u32 G, C, P; std::string S; // dp table void run() { using namespace std; // your code here cin >> G >> C >> P; cin >> S; sort(ALL(S)); i32 ans = 0; for (int i = 0; i < static_cast(S.size()); i++) { if (S[i] == 'C') { if (G > 0) { G--; ans+=3; } else if (C > 0) { C--; ans++; } } else if (S[i] == 'P') { if (C > 0) { C--; ans+=3; } else if (P > 0) { P--; ans++; } } else { if (P > 0) { P--; ans+=3; } else if (G > 0) { G--; ans++; } } } cout << ans << endl; } int main() { run(); } #pragma endregion template