#include <bits/stdc++.h>

typedef long long ll;

using namespace std;

int N;

// dp[i] represents the maximum possible sum
// ending at index (i)
// At each transition we can either continue the 
// the previous sum (i - 1) or begin a new sum
// we choose the best option among these

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

   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;
}