package yukicoder; import java.math.BigInteger; import java.util.ArrayList; import java.util.Collections; import java.util.Scanner; public class Yuki178 { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); int a[] = new int[n]; int b[] = new int[n]; boolean flg = true; ArrayList array = new ArrayList(); for (int i = 0; i < n ; i++ ) { a[i] = scan.nextInt(); b[i] = scan.nextInt(); } scan.close(); long ans = 0; for (int i = 0; i < n ; i++ ) { ans = a[i] + 4 * b[i]; array.add(ans); } Collections.sort(array); long max = Collections.max(array); long big_ans = 0; for(long num : array){ big_ans += ((max - num) / 2); if((max - num) % 2 == 1){ flg = false; } } if (flg == true){ System.out.println(big_ans); } else { System.out.println(-1); } } }