using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Programming { class Program { static void Main(string[] args) { //入力 int N = int.Parse(Console.ReadLine()); Int64[] a = new Int64[N]; string[] str = new string[2]; for (int i = 0; i < N; i++) { str = Console.ReadLine().Split(' '); a[i] = int.Parse(str[0]) + int.Parse(str[1]) * 4; } Int64 max = a.Max(); //最長文字数 Int64 cnt = 0; foreach (var item in a) { if ((max - item)%2 == 1) { Console.WriteLine(-1); return; } else { cnt += (max - item) / 2; } } Console.WriteLine(cnt); } } }