#!/usr/bin/python from collections import Counter s = 'GCP' arr = map(int, raw_input().split()) counter = Counter(raw_input()) res = 0 for k, v in counter.items(): winpos = s.index(k) - 1 tmp = min(v, arr[winpos]) res += tmp * 3 counter[k] -= tmp arr[winpos] -= tmp for k, v in counter.items(): drawpos = s.index(k) res += min(v, arr[drawpos]) counter[k] -= tmp arr[drawpos] -= tmp print res