'use strict';

var readline = require('readline');

var rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});

var onNumber = (function() {
  var readingInput = false;
  var n;
  var data;

  return function(i) {
    if (!readingInput) {
      n = i;
      data = [];
      readingInput = true;
      return;
    }
    data.push(i);
    n--;
    if (n === 0) {
      onDataSet(data);
      readingInput = false;
    }
  };
})();

rl.on('line', function(line) {
  onNumber(Number(line.trim()));
});

function onDataSet(array) {
  console.log(maxContiguousSubarraySum(array));
}

function maxContiguousSubarraySum(array) {
  var max = -Infinity;
  var sum = 0;

  for (var i = 0; i < array.length; i++) {
    sum += array[i];
    if (sum > max) {
      max = sum;
    }
    if (sum < 0) {
      sum = 0;
    }
  }

  return max;
}