import std.stdio, std.conv, std.string, std.range, std.math, std.bigint, std.algorithm, core.bitop; void main() { auto N = readln.strip.to!int; long[] a, b; foreach (_; 0 .. N) { auto input = readln.split.to!(long[]); a ~= input[0]; b ~= input[1]; } auto widths = zip(a, b).map!"a[0]+4*a[1]"; auto diffs = widths.map!(diff => widths.reduce!max-diff); (diffs.filter!"a%2==1".empty ? diffs.sum / 2 : -1).writeln; }