#!/usr/bin/python from collections import Counter def func(pos, bai, k): tmp = min(counter[k], arr[pos]) counter[k] -= tmp arr[pos] -= tmp return tmp * bai s = 'GCP' arr = map(int, raw_input().split()) counter = Counter(raw_input()) res = sum(func(s.index(k) - 1, 3, k) for k in counter.keys()) \ + sum(func(s.index(k), 1, k) for k in counter.keys()) print res