#!/usr/bin/env python # -*- coding: utf-8 -*- hand_num = list(map(int,input().split())) hand = {'G':0,'C':1,'P':2} S = input() point = 0 for s in S: if hand_num[(hand[s] + 2)%3] > 0: hand_num[(hand[s] + 2)%3] -= 1 point += 3 elif hand_num[hand[s]] > 0: hand_num[hand[s]] -= 1 point += 1 else: hand_num[(hand[s] + 1)%3] -= 1 print(point)