#!/usr/bin/ruby N=gets.to_i a=N.times.map{ a,b=gets.split.map(&:to_i) a+4*b } if a.all?{|e|e%2==a[0]%2} ma=a.max p a.reduce(0){|s,e|s+(ma-e)/2} else p -1 end