#include using namespace std; #define int long long using ll=long long; using vi=vector; using vl=vector; using pii=pair; using pll=pair; #define ITR(v,c) for(auto v=begin(c);v!=end(c);++v) #define FORE(x,c) for(auto &x:c) #define FOR(v,a,n) for(int v=a;v<(int)(n);++v) #define REP(v,n) FOR(v,0,n) #define RREP(v,n) for(int v=((int)(n)-1);v>=0;--v) #define ALL(c) begin(c),end(c) #define RALL(c) rbegin(c),rend(c) #define SZ(c) ((int)c.size()) #define dump(...) const int DX[9]={0,1,0,-1,1,1,-1,-1,0}, DY[9]={-1,0,1,0,-1,1,1,-1,0}; const int INF=1e9*2; const long long INFLL=1e18*2; template ostream& operator << (ostream &os, const vector &v) { ITR(i,v) os<<*i<<(i==end(v)-1?"":"\n"); return os; } template istream& operator >> (istream &is, vector &v) { ITR(i,v) is>>*i; return is; } //------------------------------------------------------------------------------ signed main() { int n; cin>>n; vi b(n); cin>>b; ll left=1,m,right=1e18; while(1) { m=(left+right)/2; vi a(n+1,0); a[0]=m; int big=-1; for(int i=0; i1e18) { big=((i+3)%4!=0); } } else { a[i+1]=a[i]-b[i]; if(a[i+1]<1) { big=((i+3)%4!=0); } if(a[i+1]>1e18) { big=((i+3)%4==0); } } } if(big==0) { if(right==m) break; right=m; } else if(big==1) { if(left==m) break; left=m; } if(big==-1) { cout<