gets l=$<.map{|i|a,b=i.split;a.to_i+4*b.to_i}.sort s=0;l.map{|j|s>-1&&(d=l[-1]-j)%2<1?s+=d/2 :s=-1} p s