#include <bits/stdc++.h>
using namespace std;
vector<string> vec_splitter(string s) {
  s += ',';
  vector<string> res;
  while (!s.empty()) {
    res.push_back(s.substr(0, s.find(',')));
    s = s.substr(s.find(',') + 1);
  }
  return res;
}
void debug_out(vector<string> __attribute__((unused)) args,
               __attribute__((unused)) int idx,
               __attribute__((unused)) int LINE_NUM) {
  cerr << '\n';
}
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
  if (idx > 0)
    cerr << ", ";
  else
    cerr << "Line(" << LINE_NUM << ") ";
  stringstream ss;
  ss << H;
  cerr << args[idx] << " = " << ss.str();
  debug_out(args, idx + 1, LINE_NUM, T...);
}
void run() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);
}
const int N = 1e5 + 5, mod = 1e9 + 7, mod2 = 998244353;
int n, arr[88];
int dp[85][85 * 200 + 2000][85];
int solve(int i, int money, int have) {
  if (money < 0 || have < 0) {
    return -1e9;
  }
  if (i == n) return money;
  int &ret = dp[i][money][have];
  if (~ret) return ret;
  ret = max(0, solve(i + 1, money, have));
  if (have) {
    ret = max(ret, solve(i, money + arr[i], have - 1));
  }
  if (money >= arr[i]) {
    ret = max(ret, solve(i, money - arr[i], have + 1));
  }
  return ret;
}
int main() {
  run();
  cin >> n;
  for (int i = 0; i < (int)(n); ++i) cin >> arr[i];
  memset(dp, -1, sizeof(dp));
  cout << solve(0, 1000, 0);
}
