you = map(int,raw_input().split()) enemy = [0,0,0] s = raw_input() for i in s: if i == 'C': enemy[0] += 1 elif i == 'P': enemy[1] += 1 else : enemy[2] += 1 ans = 0 for i in range(3): t = min(you[i],enemy[i]) ans += 3 * t you[i] -= t enemy[i] -= t enemy = enemy[2:] + enemy[:2] for i in range(3): ans += min(you[i],enemy[i]) print ans