using System; using System.Collections.Generic; using System.Linq; public class yukicoder { public static decimal moji(string s) { decimal[] length = s.Split(' ').Select(x => decimal.Parse(x)).ToArray(); return length[0] + (length[1] * 4); } public static void Main() { decimal size = decimal.Parse(Console.ReadLine()); List Length = new List(); for(int i = 0; i <= size - 1; i++) { Length.Add(moji(Console.ReadLine())); } decimal count = 0; decimal 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); } }