#include #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main(){ cin.tie(0); ios::sync_with_stdio(0); ll N; cin >> N; vector A(N), B(N); rep(i,N) cin >> A[i]; rep(i,N) cin >> B[i]; if(N == 2) { if(A[0] - B[0] == -(A[1] - B[1])) { cout << abs(A[0] - B[0]) << endl; } else { cout << -1 << endl; } return 0; } // N-2ずつ減る ll sumA = accumulate(A.begin(), A.end(), 0LL); ll sumB = accumulate(B.begin(), B.end(), 0LL); if((sumB - sumA) % (N - 2) != 0) { cout << -1 << endl; return 0; } ll K = (sumA - sumB) / (N - 2); ll cnt = 0; rep(i,N) { // x + y = K // x - y = B - A // 2x = K + B - A // 2y = K - B + A if((K + B[i] - A[i]) % 2 != 0){ cout << -1 << endl; return 0; } cnt += (K + B[i] - A[i]) / 2; } if(cnt == K) { cout << cnt << endl; } else { cout << -1 << endl; } }