gets.to_i.times{ gets a=[0,0]+gets.split.group_by{|i|i}.values.map(&:size).sort cnt=0 while a[-3]>0 cnt+=t=a[-3] (1..3).each{|i|a[-i]-=t} a.sort! end p cnt }