using System; public class Hello { public static void Main() { var n = int.Parse(Console.ReadLine().Trim()); var amax = 0L; var asum = 0L; var even = 0; var odd = 0; for (int i = 0; i < n; i++) { string[] line = Console.ReadLine().Trim().Split(' '); var w = long.Parse(line[0]) + 4 * long.Parse(line[1]); asum += w; if (w % 2 == 0) even++; else odd++; amax = Math.Max(amax, w); } if ((amax % 2 == 1 && odd == n) | (amax % 2 == 0 && even == n)) { var w = (amax * n - asum) / 2L; Console.WriteLine(w); } else Console.WriteLine(-1); } }