#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long power(long long first, unsigned long long second,
                unsigned long long m) {
  if (second == 0) return 1;
  long long p = power(first, second / 2, m) % m;
  p = (p * p) % m;
  return (second % 2 == 0) ? p : (first * p) % m;
}
long long modInverse(long long a, long long m) {
  { return power(a, m - 2, m); }
}
const long long maxn = 500003;
void solve(long long tt) {
  cout << "Case #" << tt << ":"
       << "\n";
}
long long n;
long long a[89];
long long dp[3003][89][89];
long long rec(long long ind, long long c, long long s) {
  if (ind >= n) {
    return c;
  }
  if (dp[ind][c][s] != -1) return dp[ind][c][s];
  long long ret = 0;
  long long i = 0;
  while (i * a[ind] <= c) {
    ret = max(ret, rec(ind + 1, c - i * a[ind], s + i));
    i++;
  }
  i = 0;
  while (i <= s) {
    ret = max(ret, rec(ind + 1, c + i * a[ind], s - i));
    i++;
  }
  return dp[ind][c][s] = ret;
}
void s() {
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> a[i];
  memset(dp, -1, sizeof dp);
  cout << rec(0, 1000, 0);
}
signed main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  s();
  return 0;
}
