gets l=$<.map{|i|eval i.split*'+4*'} s=-1;l.map{|j|s>-1&&(d=l.max-j)%2<1?s+=d/2 :s=-1} p s