gets c=$<.map{|s|a,b=s.split.map &:to_i;a+4*b} p c.all?{|x|c[0]%2==x%2}?(c.size*c.max-c.sum)/2: -1