#include <bits/stdc++.h>
using namespace std;
long long int dp[81][81][81];
long long int solve(long long int i, long long int j, long long int n,
                    vector<long long int> v, long long int sum, long long int k,
                    long long int l) {
  if (i == n) return dp[i][k][l] = sum;
  if (dp[i][j][k] != -1) return dp[i][k][l];
  long long int curr = 0, best = sum, cnt = 0;
  while (1) {
    if (curr <= sum)
      best = max(best, solve(i + 1, j + cnt, n, v, sum - curr, i, l));
    if (cnt <= j)
      best = max(best, solve(i + 1, j - cnt, n, v, sum + curr, k, i));
    if (cnt > j && curr > sum) break;
    curr += v[i], cnt++;
  }
  return dp[i][k][l] = best;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n;
  cin >> n;
  vector<long long int> v(n);
  for (long long int i = 0; i < n; i++) cin >> v[i];
  memset(dp, -1, sizeof(dp));
  cout << solve(0, 0, n, v, 1000, 0, 0) << endl;
  return 0;
}
