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