var input = '';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
  input += chunk;
})
process.stdin.on('end', function() {
  main()
});

function main () {
  var lines = input.split('\n');
  var n = lines[0] - 0;
  var a = [];
  var i,j,k;
  var sum = 0;
  for (i=0; i <n; i++) {
    a[i] = lines[i + 1] - 0;
    a[i + n] = a[i];
    sum += a[i];
  }
  
  var max = 0;
  var min;
  var first, rest;
  for (j = 0;j < n;j++) {
    first = 0;
    rest = sum;
    for (i = 0;i < n - 2;i++){
      first += a[j + i];
      rest -= a[j + i];
      
      if(first > max && check(rest, first, j + i + 1, j + n - i)) {
        max = first;
        continue;
      }
    }
  }
  function check(rest, first, k, m) {
    var second = 0;
    while (k < m) {
      second += a[k];
      rest -= a[k];
      if (first <= rest && first <= second) {
        return true;
      }
      k++;
    }

    return false;
  }
  console.log(max);

}