#include <bits/stdc++.h>
using namespace std;

#define fo(i, x, y) for (int i = x; i <= y; ++i)
#define fd(i, x, y) for (int i = x; i >= y; --i)

#define parr(a, x, y)\
{\
	for (int i = x; i <= y; ++i) printf("%d ", a[i]);\
	printf("\n");\
}

#define pint(a) printf("%d\n", a);

typedef long long ll;

const int maxn = 2e5 + 5;
const ll inf = 1e18;

int n;
ll a[maxn], d[maxn], maxd[maxn];

int getint()
{
	char ch;
	int res = 0, p;
	while (!isdigit(ch = getchar()) && (ch ^ '-'));
	p = ch == '-'? ch = getchar(), -1 : 1;
	while (isdigit(ch))
		res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();
	return res * p;
}

int main()
{
	n = getint();
	fo(i, 1, n) a[i] = getint();
	maxd[0] = -inf;
	//mind[0] = inf;
	fo(i, 1, n)
	{
		d[i] = d[i - 1] + a[i];
		maxd[i] = max(maxd[i - 1], d[i]);
		//mind[i] = min(mind[i - 1], d[i]);
	}
	ll now = 0, ans = 0;
	fo(i, 1, n)
	{
		ans = max(ans, now + maxd[i]);
		now += d[i];
	}
	printf("%lld\n", ans);
	return 0;
}

#include<iostream>
using namespace std;
typedef long long li;
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }

int ceil2(int a){
  int ret=a,i=1;
  while((ret>>i)!=0){
    ret|=ret>>i;
    i<<=1;
  }
  ret++;
  if(a==(ret>>1)) return a;
  return ret;
}

int main(){
  int n;  cin >>n;
  int t=ceil2(n+1);
  
  auto f=[&](int a){
           return (a-1)%t+1;
         };
  auto g=[&](int a){
           return f(a)-((f(a)>n)?(t/2):0);
         };
  
  
  rep(_i,n){
    int i=_i+1;
    print(g(2*i),g(2*i+1));
  }
  
}
