module main; // https://yukicoder.me/submissions/18343 より import std; void main() { // 入力 int N = readln.chomp.to!int; auto len = new long[](N); // 各行の幅 foreach (ref l; len) { long a, b; readln.chomp.formattedRead("%d %d", a, b); l = a + 4 * b; } // 答えの計算と出力 long mx = len.maxElement; foreach (l; len) { if ((mx - l) % 2) { writeln(-1); return; } } writeln((mx * N - len.sum) / 2); }