#include <bits/stdc++.h>
const double eps = (1e-9);
using namespace std;
int dcmp(long double a, long double b) {
  return fabsl(a - b) <= eps ? 0 : (a > b) ? 1 : -1;
}
int getBit(long long num, int idx) { return ((num >> idx) & 1ll) == 1; }
int setBit1(int num, int idx) { return num | (1 << idx); }
long long setBit0(long long num, int idx) { return num & ~(1ll << idx); }
long long flipBit(long long num, int idx) { return num ^ (1ll << idx); }
void GO() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int countNumBit1(int mask) {
  int ret = 0;
  while (mask) {
    mask &= (mask - 1);
    ++ret;
  }
  return ret;
}
const int N = 80 + 5;
int a[N], n, mem[N][2000 + 5][N][5];
int solve(int pos, int bal, int cnt, int fl) {
  if (pos == n) {
    return bal;
  }
  int &ret = mem[pos][bal][cnt][fl];
  if (ret != -1) {
    return ret;
  }
  int ans = 0;
  if (bal >= a[pos] && fl != 0) {
    ans = max(ans, solve(pos, bal - a[pos], cnt + 1, 1));
  }
  if (cnt > 0 && fl != 1) {
    ans = max(ans, solve(pos, bal + a[pos], cnt - 1, 0));
  }
  ans = max(ans, solve(pos + 1, bal, cnt, 2));
  return ret = ans;
}
int main() {
  GO();
  int T;
  T = 1;
  while (T--) {
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    memset(mem, -1, sizeof(mem));
    cout << solve(0, 1000, 0, 2) << "\n";
  }
}
