using System; using System.Collections.Generic; using System.Linq; public class yukicoder { public static int moji(string s) { int[] length = s.Split(' ').Select(x => int.Parse(x)).ToArray(); return length[0] + (length[1] * 4); } public static void Main() { int size = int.Parse(Console.ReadLine()); List Length = new List(); for(int i = 0; i <= size - 1; i++) { Length.Add(moji(Console.ReadLine())); } int count = 0; int max = Length.Max(); if(Length.Any(x => (max - x) % 2 != 0)) { Console.WriteLine("-1"); return; } for(int i = 0; i <= Length.Count - 1; i++) { count += (max - Length[i]) / 2; } Console.WriteLine(count); } }