me = map(int, raw_input().split()) hands = raw_input() opp = [hands.count("G"), hands.count("C"), hands.count("P")] score = 0 for i in range(3): win = min(me[i], opp[(i+1)%3]) score += win * 3 me[i] -= win opp[(i+1)%3] -= win for i in range(3): draw = min(me[i], opp[i]) score += draw * 1 me[i] -= draw opp[i] -= draw print score