#!/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 v -= tmp drawpos = s.index(k) res += min(v, arr[drawpos]) print res