#include <bits/stdc++.h>
using namespace std;
const int N = 81;
const int M = 16e3 + 10;
int memo[N][M][N];
int A[N];
int n;
int dp(int idx, int c, int s) {
  if (idx > n) return c;
  int &ret = memo[idx][c][s];
  if (ret != -1) return ret;
  ret = 0;
  if (A[idx] <= c) {
    ret = max(ret, dp(idx, c - A[idx], s + 1));
    ret = max(ret, dp(idx + 1, c - A[idx], s + 1));
  }
  if (s) {
    ret = max(ret, dp(idx, c + A[idx], s - 1));
    ret = max(ret, dp(idx + 1, c + A[idx], s - 1));
  }
  ret = max(ret, dp(idx + 1, c, s));
  return ret;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> A[i];
  memset(memo, -1, sizeof(memo));
  cout << dp(1, 1000, 0);
  return 0;
}
