#include #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; typedef long long ll; typedef vector vi; typedef vector vl; #define INF __INT32_MAX__ int main() { int N; cin >> N; vi A(N), B(N); ll suma = 0, sumb = 0; rep(i, N) { cin >> A[i]; suma += A[i]; } rep(i, N) { cin >> B[i]; sumb += B[i]; } if (N == 2) { if (A[0] + A[1] != B[0] + B[1]) { cout << -1 << endl; } else { cout << abs(A[0] - B[0]) << endl; } return 0; } if (suma < sumb || (suma - sumb) % (N - 2) != 0) { cout << -1 << endl; return 0; } bool ok = true; ll v = (suma - sumb) / (N - 2); ll sump = 0; rep(i, N) { ll p = B[i] - (A[i] - v); if (p < 0 || p % 2 != 0) { ok = false; break; } sump += p; } if (sump != 2 * v) ok = false; if (!ok) { cout << -1 << endl; } else { cout << v << endl; } }