using System; public class Hello { public static void Main() { var n = int.Parse(Console.ReadLine().Trim()); var a = new int[n]; var amax = 0; for (int i = 0; i < n; i++) { string[] line = Console.ReadLine().Trim().Split(' '); a[i] = int.Parse(line[0]) + 4 * int.Parse(line[1]); amax = Math.Max(amax, a[i]); } var ans = 0; for (int i = 0; i < n; i++) { var w = amax - a[i]; if (w % 2 == 1) { Console.WriteLine(-1); goto end; } else ans += w / 2; } Console.WriteLine(ans); end:; } }