from collections import deque g, c, p = map(int, input().split()) S = input() fg = S.count('G') fc = S.count('C') fp = S.count('P') yuki = [g, c, p] friend = [fc, fp, fg] ans = 0 result_y = [] result_f = [] for j, k in zip(yuki, friend): if j > k: ans += k * 3 result_y.append(j - k) result_f.append(0) elif k > j: ans += j * 3 result_y.append(0) result_f.append(k - j) else: ans += j * 3 result_y.append(0) result_f.append(0) result_f = deque(result_f) result_f.rotate(1) result_f = list(result_f) for n, m in zip(result_y, result_f): if n > m: ans += m elif m > n: ans += n else: ans += n print(ans)