A=gets.split.map &:to_i gets B=%w(G C P).map{|c|$_.count(c)} s=0 I=0..2 I.map{|i|t=[A[i],B[i-2]].min;s+=t*3;A[i]-=t;B[i-2]-=t} I.map{|i|s+=[A[i],B[i]].min} p s