# -*- coding:utf-8 -*- import collections if __name__ == "__main__": jibun = map(int,raw_input().split())#g,c,p s = raw_input() aite = [0,0,0] aite[0] = s.count("C") aite[1] = s.count("P") aite[2] = s.count("G") ans = 0 for i in xrange(3): #勝ち点取得 temp = min(jibun[i],aite[i]) ans += temp * 3 jibun[i] -= temp aite[i] -= temp aite = aite[2:3] + aite[0:2] for i in xrange(3): temp = min(jibun[i],aite[i]) ans += temp print ans