g, c, p = gets.strip.split.map{|e| e.to_i} hands = {G:g, C:c, P:p} s = gets.strip score = 0 s.each_char { |chr| case chr when 'P' if hands[:C] > 0 score += 3 hands[:C] -= 1 elsif hands[:P] > 0 score += 1 hands[:P] -= 1 elsif hands[:G] > 0 hands[:G] -= 1 end when 'C' if hands[:G] > 0 score += 3 hands[:G] -= 1 elsif hands[:C] > 0 score += 1 hands[:C] -= 1 elsif hands[:G] > 0 hands[:P] -= 1 end when 'G' if hands[:P] > 0 score += 3 hands[:P] -= 1 elsif hands[:G] > 0 score += 1 hands[:G] -= 1 elsif hands[:C] > 0 hands[:C] -= 1 end end } puts score