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} A.zip(B).map{|x|s+=x.min} p s