#pragma GCC         optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include            <bits/stdc++.h>
#include            <ext/pb_ds/assoc_container.hpp>
#include            <ext/pb_ds/tree_policy.hpp>
#define FastIO      ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define pb          push_back
#define eb          emplace_back
#define mp          make_pair
#define mem(x,i)    memset(x,i,sizeof(x))
#define ff          first
#define ss          second
#define popcount(x) __builtin_popcount(x)
#define all(x)      x.begin(),x.end()
#define Case(t)     for(int ks=1;ks<=t;ks++)
#define fileout     freopen("output.txt","w",stdout)
#define filein      freopen("input.txt","r",stdin)
#define D(x)        cerr<< __LINE__ <<": "<< #x << " = "<<(x) <<'\n';
#define E(x,y)      cerr<< __LINE__ <<": "<< #x << " = "<<(x)<<' '<< #y << " = "<<(y) <<'\n';
#define DE(x,y,z)      cerr<< __LINE__ <<": "<< #x << " = "<<(x)<<' '<< #y << " = "<<(y) <<' '<< #z << " = "<<(z) <<'\n';
#define endl        '\n'
///Input-Output
#define si(x)       scanf("%d",&x)
#define sii(x,y)     scanf("%d%d",&x,&y)
#define sl(x)       scanf("%lld",&x)
#define sll(x,y)     scanf("%lld%lld",&x,&y)
///
using namespace std;
using namespace __gnu_pbds;

using ll  = long long;
using ld  = long double;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pil = pair<int,ll>;


const int INF    = 0x3f3f3f3f;
const ll LL_INF  = 0x3f3f3f3f3f3f3f3f;
const double PI  = acos(-1.0);
const double eps = 1e-8;
const int mod    =1e9+7;
const int mx     = 2e5+5;
const int lg     = 26;

/*template <typename T>  using orderedSet =
    tree<T, null_type, less<T>,
    rb_tree_tag, tree_order_statistics_node_update>;
    /*order_of_key(k) - number of element strictly less than k.
     find_by_order(k) - k'th element in set.(0 indexed)(iterator)*/

/*------------------------------Graph Moves----------------------------*/
const int fx[]= {+1,-1,+0,+0};
const int fy[]= {+0,+0,+1,-1};
//const int fx[]= {+0,+0,+1,-1,-1,+1,-1,+1};  // Kings Move
//const int fy[]= {-1,+1,+0,+0,+1,+1,-1,-1}; // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/
//template<typename T>inline T gcd(T a, T b){T c;while (b){c = b;b = a % b;a = c;}return a;}
//ll powmod(ll a,ll b){ll res=1;a%=mod;assert(b>=0);for(; b; b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
/*----------------------BitMask-----------------------------------------*/
//inline int setBit(int N,int pos){return N=N | (1<<pos);}
//inline int resetBit(int N,int pos){return N= N & ~(1<<pos);}
//inline bool checkBit(int N,int pos){return (bool) (N& (1<<pos));}

int main()
{
    int n;
    cin>>n;
    ll curPos=0;
    ll sum = 0;
    ll maxTill = 0;
    ll ans = 0;
    for(int i=0;i<n;i++)
    {
        ll val;
        cin>>val;
        sum+=val;
        maxTill = max(sum,maxTill);
        ans = max(ans,curPos+maxTill);
        curPos+=sum;
    }
    cout<<ans<<endl;
}

#include <iostream>
#include <vector>
using namespace std;

int main(){
    int N; cin >> N;
    vector<long long> A; long long a; for (long long i=0; i<N; i++) { cin >> a; A.push_back(a); }

    long long pos = 0, pos_max = 0;
    long long move = 0, move_max = 0;
    for (int i=0; i<N; i++) {
        move += A[i];
        move_max = max(move_max, move);
        pos_max = max(pos_max, pos + move_max);
        pos += move;
    }

    cout << pos_max << endl;

    return 0;
}