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