import sys def debug(x, table): for name, val in table.items(): if x is val: print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr) return None def solve(): gcp_y = [int(i) for i in input().split()] gcp_em = [0, 0, 0] hands = input().rstrip() for hand in hands: if hand == 'G': gcp_em[0] += 1 elif hand == 'C': gcp_em[1] += 1 else: gcp_em[2] += 1 score = 0 kati = 0 for i in range(3): if gcp_y[i] > gcp_em[(i + 1) % 3]: kati += gcp_em[(i + 1) % 3] gcp_y[i] -= gcp_em[(i + 1) % 3] gcp_em[(i + 1) % 3] = 0 else: kati += gcp_y[i] gcp_em[(i + 1) % 3] -= gcp_y[i] gcp_y[i] = 0 score += kati * 3 aiko = 0 for i in range(3): if gcp_y[i] > gcp_em[i]: aiko += gcp_em[i] gcp_y[i] -= gcp_em[i] gcp_em[(i + 1) % 3] = 0 else: aiko += gcp_y[i] gcp_em[i] -= gcp_y[i] gcp_y[i] = 0 score += aiko * 1 print(score) if __name__ == '__main__': solve()