/* -*- coding: utf-8 -*- * * 1120.cc: No.1120 Strange Teacher - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 100000; /* typedef */ typedef long long ll; /* global variables */ int as[MAX_N], bs[MAX_N]; /* subroutines */ /* main */ int main() { int n; scanf("%d", &n); ll asum = 0, bsum = 0, psum = 0, maxm = 0; for (int i = 0; i < n; i++) scanf("%d", as + i), asum += as[i]; for (int i = 0; i < n; i++) { scanf("%d", bs + i), bsum += bs[i]; if (as[i] < bs[i]) psum += bs[i] - as[i]; else if (maxm < as[i] - bs[i]) maxm = as[i] - bs[i]; } int d = n - 2; ll f = asum - bsum; //printf("d=%d, f=%lld\n", d, f); if (d == 0) printf("%lld\n", (f == 0) ? psum : -1LL); else if (f >= 0 && f % d == 0) { ll r = f / d; printf("%lld\n", (psum <= r && maxm <= r) ? r : -1); } else puts("-1"); return 0; }