import java.io.BufferedReader; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); String[] sa = br.readLine().split(" "); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = Integer.parseInt(sa[i]); } sa = br.readLine().split(" "); int[] b = new int[n]; for (int i = 0; i < n; i++) { b[i] = Integer.parseInt(sa[i]); } br.close(); long sum = 0; int[] d = new int[n]; for (int i = 0; i < n; i++) { d[i] = a[i] - b[i]; sum += d[i]; } if (n == 2) { if (sum == 0) { System.out.println(Math.abs(d[0])); } else { System.out.println(-1); } return; } if (sum < 0 || sum % (n - 2) != 0) { System.out.println(-1); return; } int cnt = (int) (sum / (n - 2)); int sum2 = 0; for (int i = 0; i < n; i++) { int val = (cnt - d[i]) / 2; if (val < 0) { System.out.println(-1); return; } sum2 += val; } if (sum2 == cnt) { // System.out.println(cnt); throw new Exception(); } else { System.out.println(-1); } } }