#include enum GCP { G, C, P }; int mGCP[3]; int eGCP[3]; int w[3]; int d[3]; char S[500]; int main() { int sum = 0; scanf( "%d %d %d\n", mGCP+G, mGCP+C, mGCP+P ); scanf( "%s\n", S ); for( int i; S[i] != '\0'; i++ ) { switch( S[i] ) { case 'G': eGCP[G]++; break; case 'C': eGCP[C]++; break; case 'P': eGCP[P]++; break; default: break; } } #ifdef DEBUG printf("mGCP %d %d %d\n", mGCP[G], mGCP[C], mGCP[P] ); printf("eGCP %d %d %d\n", eGCP[G], eGCP[C], eGCP[P] ); #endif w[G] = mGCP[G] > eGCP[C] ? eGCP[C] : mGCP[G]; w[C] = mGCP[C] > eGCP[P] ? eGCP[P] : mGCP[C]; w[P] = mGCP[P] > eGCP[G] ? eGCP[G] : mGCP[P]; sum += w[G]*3; sum += w[C]*3; sum += w[P]*3; mGCP[G] -= w[G]; mGCP[C] -= w[C]; mGCP[P] -= w[P]; eGCP[G] -= w[P]; eGCP[P] -= w[C]; eGCP[C] -= w[G]; #ifdef DEBUG printf("w %d %d %d\n", w[G], w[C], w[P] ); #endif d[G] = mGCP[G] > eGCP[G] ? eGCP[G] : mGCP[G]; d[C] = mGCP[C] > eGCP[C] ? eGCP[C] : mGCP[C]; d[P] = mGCP[P] > eGCP[P] ? eGCP[P] : mGCP[P]; sum += d[G]; sum += d[C]; sum += d[P]; #ifdef DEBUG printf("d %d %d %d\n", d[G], d[C], d[P] ); #endif printf("%d\n", sum ); return 0; }