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!int; auto abi = iota(n) .map!(_ => readln.split.map!(to!int)) .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)); } int calc(int[] li) { auto r = 0; auto m = li.front; foreach (l; li) if ((m - l) % 2 == 1) return -1; else r += (m - l) / 2; return r; }