#include <iostream>
#include <bits/stdc++.h>
#include <bitset>
#define ll long long int
#define pi pair<int, int>
#define pll pair<ll, ll>
#define pb push_back 
#define vi vector<int>
#define vl vector<ll>
#define vll vector<vl>
#define vpi vector<pi>
#define vpll vector<pll>
#define vb vector<bool>
#define vii vector<vi>
#define ALL(v) v.begin(), v.end()
#define st string
#define si(n) cin >> n
#define dout(n) cout << n << "\n"
#define mod 1000000007
#define f(i, a, b) for (int i = a; i < b; i++)
#define fd(i, a, b) for (int i = a; i >= b; i--)

using namespace std;

bool yes = false;
st s1, s2;

ll max(ll a, ll b, ll c)
{
    return max(a, max(b, c));
}

struct comp
{

    bool operator()(const pi &a, const pi &b)
    {
        if (a.first == b.first)
            return a.second < b.second;
        return a.first < b.first;
    }
};

bool check_pal(st &s)
{
    int i = 0, j = s.length() - 1;
    while (i < j)
    {
        if (s[i] != s[j])
            return false;
        i++, j--;
    }
    return true;
}
void swap(char &a, char &b)
{
    char ch = a;
    a = b;
    b = ch;
    return;
}
int dfs(vii &g, vi &vis, vi &co, int pos)
{

    int mn = co[pos];
    vis[pos] = 1;
    f(i, 0, g[pos].size())
    {
        if (!vis[g[pos][i]])
            mn = min(dfs(g, vis, co, g[pos][i]), mn);
    }
    return mn;
}

void seive(int n, vector<bool> &isprime)
{
    isprime[0] = true;
    isprime[1] = true;
    f(i, 2, n + 1)
    {
        if (!isprime[i])
        {

            for (int j = 2; (j * i) < n + 1; j++)
                isprime[j * i] = true;
        }
    }
}
int findfact( int n , int&a , int &b){
    for( int i =2 ;i<n ; i++){
        if( n%i == 0 && i!=n/i) {
            a=i;
            b = n/i ;
            return 0;
        }
    }
    return -1;
}
ll ignoref(vi & v, int mx , int fmx , vi & con, int idx){
ll op=0;
int n = v.size();
int prev = idx == 0? v[1]:v[0];
if( fmx==1){
      f(i,1,n){
           if( v[i]!=mx){
                 op+= abs(v[i]-prev);
                 //cout<<op<<" ";
                 prev = v[i];
           }
         
       }
}
else {
    int index;
    int mxcon=INT_MIN;
    f(i,0,n){
        if(v[i]==mx){
            if( mxcon <con[i]){
                index =i;
                mxcon = con[i];
            }
        }
    }
    f(i,1,n){
           if( i!= index){
                 op+= abs(v[i]-prev)*1ll;
               //  cout<<op<<" "<<v[i]<<" "<<prev<<" \n";
                 prev = v[i];
           }
         
       }
}
return op;
}

int main()
{
   
 int n;
 cin>>n;
 vi v;
 f(i,0,n){
     int a;
     cin>>a;
     v.pb(a);
 }
 vector<pair<ll,ll>>pssum(n);
 ll msf=0,mx=0;
 f(i,0,n){
     msf+=v[i];
     mx = max(mx,msf);
     pssum[i].first = mx;
     pssum[i].second = msf;
 }
 ll ans = 0;
 msf =0;
 f(i,0,n){
     ans = max(msf+pssum[i].first, ans);
    msf+=pssum[i].second;
   
 }
 ans = max(msf,ans);
 cout<<ans<<"\n";
}

#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#define LL long long
using namespace std;
LL maxx[400000], arr[400000];
int main (){
    LL n;
    cin >> n;
    for (LL i = 1;i <= n; ++ i){
        scanf("%lld", &arr[i]);
    }
    LL max_ = arr[1];
    maxx[1] = max_;
    for (LL i = 2;i <= n; ++ i){
        arr[i] += arr[i - 1];
        maxx[i] = max_ = max(max_, arr[i]);
        // cout << arr[i]<<" "<<maxx[i]<<endl;
    }
    LL x = 0, ans = 0;
    for (LL i = 1;i <= n; ++ i){
        // cout << x;
        ans = max(ans, x + maxx[i]);
        x += arr[i];
    }
    cout << ans;
    return 0;
}