#include <iostream>
#include <algorithm>
using namespace std;
const int N = 1e6 + 1;
long long pre[N],a[N];
int n;
int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= n; i++) a[i] = a[i - 1] + a[i];
    for (int i = 1; i <= n; i++) pre[i] = pre[i - 1] + a[i];
    long long res = 0 , value = 0;
    for (int i = 1; i <= n; i++){
        value = max(value,a[i]);
        res = max(res,pre[i - 1] + value);
    }
    cout << res;
    return 0;
}

/*
Solved by sid2104
on 11/11/2020  22:32 
*/
#include <bits/stdc++.h>
using namespace std;
#define int         long long
#define float       long double
#define pb          push_back
#define ld          long double
#define f(i,a,b)    for(int i=a;i<b;i++)
#define mp          make_pair
#define pii         pair<int,int>
#define vi          vector<int>
#define vpii         vector<pair<int,int> >
#define mii         map<int,int>
#define all(a)      (a).begin(),(a).end()
#define debug(x)    cout<<#x<<" is "<<(x)<<endl;cout.flush();
//#define debug(x)    ;
//#define debug(x)    ;
// === Debug macro starts here ===

int recur_depth = 0;
#ifdef DEBUG
#define dbg(x) {++recur_depth; auto x_=x; --recur_depth; cerr<<string(recur_depth, '\t')<<"\e[91m"<<__func__<<":"<<__LINE__<<"\t"<<#x<<" = "<<x_<<"\e[39m"<<endl;}
#else
#define dbg(x)
#endif
template<typename Ostream, typename Cont>
typename enable_if<is_same<Ostream,ostream>::value, Ostream&>::type operator<<(Ostream& os,  const Cont& v){
    os<<"[";
    for(auto& x:v){os<<x<<", ";}
    return os<<"]";
}
template<typename Ostream, typename ...Ts>
Ostream& operator<<(Ostream& os,  const pair<Ts...>& p){
    return os<<"{"<<p.first<<", "<<p.second<<"}";
}

// === Debug macro ends here ===
#define mp          make_pair
#define x           first
#define y           second
#define pb          push_back
#define endl        '\n'
#define si(x)       (int)((x).size())
#define IOS         ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define txt         freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define elasped_time 1.0 * clock() / CLOCKS_PER_SEC
#define tree        vector<vector<int> >
#define PI          3.14159265358979323846
int inf=99999999999;
const int mod=1e9+7;
const int cmp=1e17;
inline int gcd(int a, int b) {
  while (a > 0 && b > 0) {
    if (a > b) a %= b;
    else b %= a;
  }
  return a + b;
}
void inp(int n,int arr[])
{
    f(i,0,n) cin>>arr[i];
}
int ans=0;
void solve()
{
  int sum=0;
  int curr=0;
  int currm=0;
  int n;
  cin>>n;
   f(i,0,n)
   {
     int k;
     cin>>k;
     curr+=k;
 
     currm=max(curr,currm);
     ans=max(ans,sum+currm);
     sum+=curr;
    
   }
   cout<<ans<<endl;
        
}
main()
{
    IOS;
    solve();
  

}








