#include using namespace std; #define int long long const int MOD = 1000000007; signed main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vector A(N); vector B(N); int sumA = 0; int sumB = 0; for (int i = 0; i < N; i++) { cin >> A[i]; sumA += A[i]; } for (int i = 0; i < N; i++) { cin >> B[i]; sumB += B[i]; } if (N == 2) { if (sumA != sumB) { cout << -1 << endl; } else { cout << abs(A[0] - B[0]) << endl; } } else { bool ok = true; if (sumA < sumB) { ok = false; } else { int k = sumA - sumB; if (k % (N - 2) != 0) { ok = false; } else { int tot = k / (N - 2); int c = 0; for (int i = 0; i < N; i++) { int t = (B[i] - A[i] + tot); if (t < 0 || t % 2 != 0) { ok = false; } int x = t / 2; A[i] += x - (tot - x); c += x; } if (c != tot) { ok = false; } if (ok) { cout << tot << endl; return 0; } } } if (!ok) { cout << -1 << endl; } } }