#include #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--) #define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++) #define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--) #define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++) #define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++) #define ALL(x) x.begin(), x.end() using ll = long long; using namespace std; int main(){ int n; cin >> n; vector a(n); rep(i, n) cin >> a.at(i); vector b(n); rep(i, n) cin >> b.at(i); ll suma = 0, sumb = 0; ll ans = 0, diff = 0; rep(i, n){ if(b.at(i)-a.at(i) > 0) ans += b.at(i)-a.at(i); else diff += a.at(i)-b.at(i); suma += a.at(i); sumb += b.at(i); } if(n == 2){ if(suma != sumb){ cout << -1 << endl; return 0; } }else{ cerr << suma << " " << sumb << " " << ans << " " << diff << endl; if(suma < sumb || (suma - sumb) % (n-2) != 0){ cout << -1 << endl; return 0; } ans = (suma-sumb)/(n-2); ll co = 0; rep(i, n){ a.at(i) -= ans; if((b.at(i) - a.at(i)) % 2 != 0){ cout << -1 << endl; return 0; } co += (b.at(i)-a.at(i))/2; } if(co != ans){ cout << -1 << endl; return 0; } } cout << ans << endl; return 0; }