// writer解のコピペ改変 #include using namespace std; long long N, A[1 << 18], B[1 << 18], P[1 << 18]; int main() { cin >> N; for (int i = 1; i <= N; i++) cin >> A[i]; for (int i = 1; i <= N; i++) cin >> B[i]; assert(2 <= N && N <= 100000); for (int i = 1; i <= N; i++) assert(0 <= A[i] && A[i] <= 1000000); for (int i = 1; i <= N; i++) assert(0 <= B[i] && B[i] <= 1000000); // N = 2 の場合 if (N == 2LL) { if (A[1] + A[2] != B[1] + B[2]) cout << "-1" << endl; else cout << abs(A[1] - B[1]) << endl; return 0; } // そうでない場合 long long SA = 0, SB = 0, V = 0; for (int i = 1; i <= N; i++) SA += A[i]; for (int i = 1; i <= N; i++) SB += B[i]; if (SA < SB || (SA - SB) % (N - 2LL) != 0) { cout << "-1" << endl; return 0; } V = (SA - SB) / (N - 2LL); long long cnt = 0; for (int i = 1; i <= N; i++) P[i] = B[i] - (A[i] - V); for (int i = 1; i <= N; i++) { // if (P[i] % 2 == 1 || P[i] < 0) { cout << "-1" << endl; return 0; } if (P[i] < 0) { cout << "-1" << endl; return 0; } cnt += P[i]; } if (cnt != 2LL * V) cout << "-1" << endl; else cout << V << endl; return 0; }