#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } //constexpr long long MAX = 5100000; constexpr long long INF = 1LL << 60; constexpr int inf = 1000000007; //constexpr long long mod = 1000000007LL; constexpr long long mod = 998244353LL; const long double PI = acos((long double)(-1)); using namespace std; typedef unsigned long long ull; typedef long long ll; typedef long double ld; void fail() { puts("-1"); exit(0); } int main() { /* cin.tie(nullptr); ios::sync_with_stdio(false); */ int n; scanf("%d", &n); ll suma = 0, sumb = 0; vector a(n); for (int i = 0; i < n; i++) scanf("%lld", &a[i]), suma += a[i]; vector b(n); for (int i = 0; i < n; i++) scanf("%lld", &b[i]), sumb += b[i]; if (suma < sumb) fail(); if (n == 2) { if (suma != sumb) fail(); printf("%lld\n", llabs(a[0] - b[0])); return 0; } ll sa = suma - sumb; if (sa % (n - 2) != 0) fail(); ll cnt = sa / (n - 2); ll res = cnt; for (int i = 0; i < n; i++) { a[i] -= cnt; } for (int i = 0; i < n; i++) { if (a[i] > b[i]) fail(); if ((b[i] - a[i]) % 2 == 1) fail(); ll t = (b[i] - a[i]) / 2; if (cnt < t) fail(); cnt -= t; } cout << res << endl; return 0; }