#pragma GCC optimize ("O2") #pragma GCC optimize ("tree-vectorize") #pragma GCC target ("sse4") #include #define FOR(i, a, b) for(int i=(a);i<(b);++i) #define FFOR(i, a, b) FOR(i, a, b+1) #define REP(i, n) FOR(i, 0, n) #define RREP(i, n) FOR(i, 1, n+1) #define ALL(v) (v).begin(), (v).end() #define RALL(v) (v).rbegin(), (v).rend() #define LEN(x) (int)(x).size() #define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<; using pll = pair; template using vc = vector; template using vvc = vector>; template inline bool chmax(T &a, T b){if(a inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;} const double PI = acos(-1); constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;} class Task{ public: void solve(istream& in, ostream& out){ int N; in>>N; lint sa = 0, sb = 0; vc A(N), B(N); REP(i, N) in>>A[i], sa += A[i]; REP(i, N) in>>B[i], sb += B[i]; if(N==1){ if(sa<=sb) out<sa or (sa-sb)%(N-2)!=0){ out<<"-1\n"; return; } bool ok = true; lint x = (sa-sb) / (N-2); REP(i, N){ if(abs(A[i]-B[i])>x) ok = false; } if(ok) out<