#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i ) #define rep(i,n) REP(i,0,n) using ll = long long; typedef pair pint; typedef pair pli; const int inf=1e9+7; const ll longinf=1LL<<60 ; const ll mod=1e9+7 ; int main(){ int n; cin >> n; ll a[n], b[n], sa[n]; rep(i, n){ cin >> a[i]; } rep(i, n){ cin >> b[i]; } ll sum = 0; rep(i, n){ sa[i] = a[i]-b[i]; sum+=sa[i]; } if(n==2){ if(sum!=0) cout << -1 << endl; else cout << sa[0] << endl; return 0; } bool can = true; if(sum%(n-2)!=0) can = false; if(sum<0) can = false; //cout << can << endl; rep(i, n-1){ if(abs(sa[i])%2!=abs(sa[i+1])%2) can=false; } sort(sa, sa+n, greater<>()); ll kai[n]; kai[0] = 0; ll k = 0; rep(i, n-1){ kai[i+1] = kai[i]+(sa[i]-sa[i+1])/2; k+=kai[i+1]; //cout << kai[i+1] << endl; } if(k>sum/(n-2)) can=false; if(can) cout << sum/(n-2) << endl; else cout << -1 << endl; }