#include using namespace std; using ll = long long; template using vec = vector; template using vvec = vector>; int main(){ cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vec A(N),B(N); ll asum = 0,bsum = 0; for(auto& x:A){ cin >> x; asum += x; } for(auto& x:B){ cin >> x; bsum += x; } if(N==2){ assert(false); ll d0 = A[0]-B[0],d1 = A[1]-B[1]; cout << ((d0+d1==0)? abs(d0):-1) << "\n"; return 0; } if((asum-bsum)%(N-2)!=0){ cout << -1 << "\n"; return 0; } ll ans = (asum-bsum)/(N-2); ll cnt = 0; for(int i=0;i