#include using namespace std; #define ll long long #define all(x) x.begin(),x.end() #define rep(i,a,b) for(int i=a;i<=b;i++) #define rep_r(i,a,b) for(int i=a;i>=b;i--) #define each(a,x) for (auto& x : a) using pi = pair; using pl = pair; using vi = vector; using vl = vector; #define sz(x) int(x.size()) #define so(x) sort(all(x)) #define so_r(x) sort(all(x),greater()) #define lb lower_bound #define ub upper_bound const char nl = '\n'; int dx[4] = {1,-1,0,0}; int dy[4] = {0,0,1,-1}; int bit_cnt(int x){ return __builtin_popcount(x); } ll bex(ll a, ll b, ll mod = 1e9 + 7){ll res = 1LL; while(b){ if (b&1) res = res * a % mod; a = a * a % mod; b >>= 1;} return res;} template bool chmax(t&a,u b){if(a bool chmin(t&a,u b){if(b> n; rep(i,1,n) cin >> a[i]; rep(i,1,n) cin >> b[i]; ll dif = 0; rep(i,1,n) dif+=a[i]-b[i]; // each operation will make total points decrease n-2 // => dif % (n-2) == 0 // and dif > 0 // special case is n == 2 // => dif == 0 if (n == 2){ if (dif != 0) cout << -1 << nl; cout << abs(a[1] - b[1]) << nl; return; } if (dif % (n-2) != 0 || dif < 0){ cout << -1 << nl; return; } ll operations = dif / (n-2); // number of operations will be used // add[i] is the number of operations teacher use for increasing point for student[i] // b[i] = a[i] - operations + 2 * add[i] vl add(n+1); rep(i,1,n){ ll tmp = b[i] - a[i] + operations; if (tmp % 2 == 1) { cout << -1 << nl; return; } add[i] = tmp / 2; } ll tot = operations; rep(i,1,n){ tot -= add[i]; } if (tot != 0) { cout << -1 << nl; } else { cout << operations << nl; } } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; // cin >> t; while (t--){ solve(); } }