#include <bits/stdc++.h>
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
using namespace std;
mt19937 mrand(random_device{}());
const long long mod = 1000000007;
int rnd(int x) { return mrand() % x; }
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long modInverse(long long a) {
  long long p = mod - 2;
  return powmod(a, p);
}
void recurse(int i, int j, int k, vector<vector<vector<int>>>& dp,
             vector<int>& a) {
  if (dp[i][j][k] != -1) return;
  recurse(i + 1, j, k, dp, a);
  dp[i][j][k] = dp[i + 1][j][k];
  for (int sell = 1; sell < j + 1; sell++) {
    recurse(i + 1, j - sell, k + a[i] * sell, dp, a);
    dp[i][j][k] = max(dp[i][j][k], dp[i + 1][j - sell][k + a[i] * sell]);
  }
  for (int pur = 1; pur < k / a[i] + 1; pur++) {
    recurse(i + 1, j + pur, k - a[i] * pur, dp, a);
    dp[i][j][k] = max(dp[i][j][k], dp[i + 1][j + pur][k - a[i] * pur]);
  }
}
void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto& x : a) cin >> x;
  vector<vector<vector<int>>> dp(
      n + 1, vector<vector<int>>(5 * n, vector<int>(40001, -1)));
  for (int j = 0; j < 50001; j++)
    for (int k = 0; k < 11 * n; k++) dp[n][k][j] = j;
  recurse(0, 0, 1000, dp, a);
  cout << dp[0][0][1000] << "\n";
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL);
  solve();
}
