#include <bits/stdc++.h>
using namespace std;
#define ios ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define ll long long
const int maxN = 1e5;
int a[maxN];

ll recur(int l, int r){
    if(l + 1 >= r) return a[l];
    
    int mid = (l + r) / 2;
    ll ans = max(recur(l, mid), recur(mid, r));
    ll ansL = LONG_LONG_MIN, ansR = LONG_LONG_MIN;
    ll now = 0;
    for(int i = l; i < mid; i++){
        now += a[i];
        ansL = max(ansL, now);
    }
    now = 0;
    for(int i = mid; i < r; i++){
        now += a[i];
        ansR = max(ansR, now);
    }   
    ll sum = max(ansL, max(ansR, ansL + ansR));
    ans = max(ans, sum);
    cout << l << " " << r << " " << ansL << " " << ansR << endl;
    return ans; 
    
    
    
    
    
}
signed main(){
    ios;
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    cout << recur(0, n) << endl;
}