#include using namespace std; void fail(){ cout << -1 << endl; exit(0); } int main(){ int N; cin >> N; vector A(N); for(int i=0; i> A[i]; for(int i=0; i> a; A[i] = a-A[i]; } auto S = accumulate(A.begin(), A.end(), 0LL); if(S > 0) fail(); if(N == 2){ if(S) fail(); cout << abs(A[0]) << endl; return 0; } if(S%(N-2)) fail(); int64_t T = -S/(N-2); int64_t t = 0; for(int64_t a : A){ a -= T; if(a > 0 || a%2) fail(); t += -a/2; } if(t == T) fail(); cout << T << endl; return 0; }