#include using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin>>N; ll S=0; vector A(N); for(int i=0;i>A[i]; } for(int i=0;i>a; A[i]=a-A[i]; S+=A[i]; } if(N==2){ cout<<(S==0?abs(A[0]):-1)<0||abs(S)%(N-2)!=0){ cout<<-1<