import std.stdio; import std.algorithm; import std.conv; import std.array; import std.string; void main() { auto n = readln().chomp.to!uint; uint max = 0; uint[] lines; foreach (i; 0..n) { auto input = readln().split().map!(to!uint); auto l = input[0] + input[1] * 4; lines ~= l; if (max < l) max = l; } uint cnt = 0; foreach (l; lines) { auto z = max - l; if (z % 2 != 0) { writeln(-1); return; } cnt += z / 2; } writeln(cnt); }