#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 3e5 + 5;
const int oo = 1e9 + 5;
const long long int ooll = (long long int)1e18 + 5;
const int MOD = 1e9 + 7;
const int M = 20005;
clock_t start = clock();
int v[N];
void solve() {
  int n;
  cin >> n;
  vector<int> dp(M, -oo), dq;
  dp[1000] = 0;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    dq = dp;
    fill(dp.begin(), dp.end(), -oo);
    for (int j = 0; j < M; ++j) {
      for (int k = 0; k * x <= j; ++k) {
        dp[j - k * x] = max(dp[j - k * x], dq[j] + k);
      }
      dp[j] = max(dp[j], dq[j]);
      int have = dq[j];
      for (int k = 0; k <= have; ++k) {
        dp[j + k * x] = max(dp[j + k * x], have - k);
      }
    }
  }
  int ans = -1;
  for (int i = 0; i < M; ++i)
    if (dp[i] >= 0) ans = i;
  cout << ans << '\n';
}
int main() {
  int T = 1;
  while (T--) {
    solve();
  }
  return 0;
}
