#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll=long long; template using V = vector; template using P = pair; using vll = V; using vvll = V; #define rep(i, k, n) for (ll i=k; i<(ll)n; ++i) #define REP(i, n) rep(i, 0, n) #define ALL(v) v.begin(),v.end() template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; } template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; } #define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<> n; V a(n), b(n); for (int i = 0; i < n; i++) cin >> a[i]; int bcnt = 0, bi; for (int i = 0; i < n; i++) { cin >> b[i]; if (b[i] > a[i]) bcnt++, bi = i; } if (bcnt == 0) { if (a == b) cout << 0 << '\n'; else cout << -1 << '\n'; } else if (bcnt > 1) { cout << -1 << '\n'; } else { int minus = b[bi] - a[bi]; bcnt = 0; int bi2; for (int i = 0; i < n; i++) { if (i != bi && b[i] + minus == a[i]) bcnt++, bi2 = i; } if (bcnt == n - 1) cout << minus << '\n'; else if (bcnt != 1) cout << -1 << '\n'; else { int ab = INF; for (int i = 0; i < n; i++) { if (i == bi || i == bi2) continue; if (ab == INF) ab = (a[i] - b[i] - minus); else { if (ab != (a[i] - b[i] - minus)) { cout << -1 << '\n'; return 0; } } } if (ab & 1) cout << -1 << '\n'; else cout << minus + ab << '\n'; } } return 0; }