# include<bits/stdc++.h>
using namespace std;
# define l long long 
# define db double 
# define rep(i,a,b) for(l i=a;i<b;i++)
# define vi vector<l>
# define pb push_back
# define mp make_pair
# define ss second
# define ff first
# define pii pair<l,l>
# define trvi(v,it) for(vi::iterator it=v.begin();it!=v.end();++it)
# define read(a) freopen(a,"r",stdin)
# define write(a) freopen(a,"w",stdout)
# define io ios::sync_with_stdio(false)
#define vertex first.second
#define dist first.first
#define parent second
const l MOD=1e9+7;
const l N=3e5+5;
const l INF=1e14;

void solve() {
	l n;
	cin>>n;
	vi a(n);
	rep(i,0,n) {
		cin>>a[i];
	}
	l prefix=0, curMax=0, maxPrefix=0;
	l sum=0;
	rep(i,0,n) {
		maxPrefix=max(maxPrefix,sum+a[i]);
		curMax=max(curMax,prefix+maxPrefix);
		// cout<<"maxPrefix,curMax,prefix "<<maxPrefix<<" "<<curMax<<" "<<prefix<<" "<<a[i]<<"\n";
		sum+=a[i];
		prefix+=sum;

	}
	cout<<curMax<<"\n";


	return;
}
int main(){
	io;
	int t;
	// cin >> t;
	rep(i,0,1) {
		solve();
	}

	return 0;
}
#include <bits/stdc++.h>

using namespace std;

#define ar array
#define ll long long

const int MAX_N = 1e5 + 1;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;

int findMaxGCD(int arr[], int n)
{
    // Calculating MAX in array
    int high = 0;
    for (int i = 0; i < n; i++)
        high = max(high, arr[i]);
 
    // Maintaining count array
    int count[high + 1] = {0};
    for (int i = 0; i < n; i++)
        count[arr[i]]++;
 
    // Variable to store the
    // multiples of a number
    int counter = 0;
 
    // Iterating from MAX to 1
    // GCD is always between
    // MAX and 1. The first
    // GCD found will be the
    // highest as we are
    // decrementing the potential
    // GCD
    for (int i = high; i >= 1; i--)
    {
        int j = i;
       counter = 0;
   
        // Iterating from current
        // potential GCD
        // till it is less than
        // MAX
        while (j <= high)
        {
            // A multiple found
 
            if(count[j] >=2)
               return j;
 
           else if (count[j] == 1)        
                counter++;        
 
            // Incrementing potential
            // GCD by itself
            // To check i, 2i, 3i....
            j += i;
 
            // 2 multiples found,
            // max GCD found
            if (counter == 2)        
                return i;
        }
    }
}

void solve() {
    int a, b; cin >> a >> b;
    int n = b - a + 1;
    int arr[n];
    for (int i = a, j = 0; i <= b; i++, j++) arr[j] = i;
    cout << findMaxGCD(arr, n) << "\n";
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int tc = 1;
    // cin >> tc;
    for (int t = 1; t <= tc; t++) {
        // cout << "Case #" << t << ": ";
        solve();
    }
}