#include <bits/stdc++.h>

typedef long long ll;

using namespace std;

int N;

ll maxSum(vector<ll> &nums) {
   ll maxS = INT_MIN;
   for (int i = 0; i < N; i++) {
        ll sum = 0;
        for (int j = i; j < N; j++) {
            sum += nums[j];
        }
        maxS = max(maxS, sum);
   }
   return maxS;
}

int main(){
   cin >> N;
   vector<ll> nums(N + 1);
   for (int i = 1; i <= N; i++) cin >> nums[i];
   cout << maxSum(nums) << endl;
   return 0;
}