class Calc0178 def initialize(args) args = args.map { |l| l.chomp.split(/\s+/) } @n = args.shift.first.to_i @lines = args.map { |l| l.map(&:to_i) } end def run ws = @lines.map { |l| l[0] + l[1] * 4 } max = ws.max ws = ws.map { |l| max - l } if ws.any?(&:odd?) -1 else ws.inject(:+) / 2 end end end puts Calc0178.new(STDIN.readlines).run if __FILE__ == $0