#include using namespace std; typedef long long ll; typedef long double ld; using P = pair; const ll mod = 1e9+7; #define ALL(x) (x).begin(),(x).end() #define REP(i,n) for(ll (i)=0;(i)<(n);(i)++) #define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++) #define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--) #define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--) #define pb push_back #define mp make_pair #define F first #define S second #define UNIQUE(v) v.erase(unique(ALL(v)),v.end()); template inline void chmin(T& a, T b){ if (a > b){ a = b; } } template inline void chmax(T& a, T b){ if (a < b){ a = b; } } signed main(){ cin.tie(0); ios::sync_with_stdio(false); cout<> N; ll sum = 0; bool ok = 1; vector A(N); vector B(N); REP(i,N)cin >> A[i]; REP(i,N)cin >> B[i]; REP(i,N)sum += A[i] - B[i]; ll count = 0; ll ans = 0; if(N == 2){ if(A[0] + A[1] != B[0] + B[1]){ ok = 0; }else{ ans = abs(A[0] - B[0]); } cout << (ok ? ans : -1) << "\n"; }else{ if(sum % (N-2) != 0){ ok = 0; }else{ count = sum / (N-2); } REP(i,N){ if(A[i] -B[i] - count > 0)ok = 0; if((A[i] -B[i] - count) %2 != 0)ok = 0; } cout << (ok ? count : -1) << "\n"; } }