#include using namespace std; #define rep(i,n) for(int i = 0; i < (n);i++) #define sz(x) int(x.size()) typedef long long ll; typedef long double ld; typedef pair P; constexpr int mod = 1e9+7; int main() { int n; cin >> n; vector a(n), b(n); rep(i,n) cin >> a[i]; rep(i,n) cin >> b[i]; if (n == 2) { if (a[0] + a[1] != b[1] + b[0]) cout << -1 << endl; else cout << abs(a[0] - b[0]) << endl; return 0; } ll suma = 0, sumb = 0; for (int i = 0; i < n; i++) suma += a[i], sumb += b[i]; if (suma < sumb || (suma - sumb) % (n - 2) != 0) { cout << -1 << endl; return 0; } ll v = (suma - sumb) / (n - 2); ll cnt = 0; for (int i = 0; i < n; i++) a[i] -= v; for (int i = 0; i < n; i++) { int d = b[i] - a[i]; if (d % 2 == 1 || d < 0) { cout << -1 << endl; return 0; } cnt += d; } if (cnt != 2LL * v) cout << -1 << endl; else cout << v << endl; return 0; }