#include #include #include void solve() { std::vector xs(3); for (auto& x : xs) std::cin >> x; std::vector ys(3); { std::string s; std::cin >> s; for (char c : s) { for (int i = 0; i < 3; ++i) { if (c == "GCP"[i]) ++ys[i]; } } } int ans = 0; for (int i = 0; i < 3; ++i) { int j = (i + 1) % 3; int g = std::min(xs[i], ys[j]); ans += g * 3; xs[i] -= g, ys[j] -= g; } for (int i = 0; i < 3; ++i) { int j = i; int g = std::min(xs[i], ys[j]); ans += g * 1; xs[i] -= g, ys[j] -= g; } std::cout << ans << std::endl; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }