#include <bits/stdc++.h>
using namespace std;
const long long N = 81;
const long long M = 17000;
long long n;
long long a[N];
long long dp[N][N][M];
long long solve(long long id, long long stoke, long long cur) {
  if (id >= n) return cur;
  long long &tmp = dp[id][stoke][cur];
  if (tmp != -1) return tmp;
  tmp = cur;
  tmp = max(tmp, solve(id + 1, stoke, cur));
  if (cur >= a[id]) tmp = max(tmp, solve(id, stoke + 1, cur - a[id]));
  if (stoke > 0) tmp = max(tmp, solve(id, stoke - 1, cur + a[id]));
  return tmp;
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> a[i];
  memset(dp, -1, sizeof dp);
  long long ans = solve(0, 0, 1000);
  ans = max(ans, 1000ll);
  cout << ans << "\n";
}
