me=gets.split.map(&:to_i) ec={'G'=>0,'C'=>1,'P'=>2} en=[0,0,0] gets.chomp.chars{|c|en[ec[c]]+=1} pt=0 3.times{|i| t=[en[i],me[i-1]].min pt+=t*3 en[i]-=t;me[i-1]-=t } 3.times{|i| t=[en[i],me[i]].min pt+=t en[i]-=t;me[i]-=t } p pt