import std.algorithm, std.array, std.container, std.range; import std.numeric, std.math, std.bigint, std.bitmanip, std.random; import std.string, std.conv, std.stdio, std.typecons; void main() { auto n = readln.chomp.to!long; auto abi = iota(n) .map!(_ => readln.split.map!(to!long)) .map!(rd => tuple(rd[0], rd[1])); auto li = abi.map!(ab => ab[0] + 4 * ab[1]).array; li.sort!("a > b"); writeln(calc(li)); } long calc(long[] li) { auto r = 0L; auto m = li.front; foreach (l; li) if ((m - l) % 2 == 1) return -1; else r += (m - l) / 2; return r; }