#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x7f7f7f7f7f7f7f7f;
const long long NINF = -INF;
const long long MAXN = 1e+6 + 8;
int dx8[] = {0, 1, 1, 1, 0, -1, -1, -1}, dy8[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0};
long long n, a[105], dp[85][205][1005];
long long solve(long long i, long long num, long long cst) {
  if (i == n) {
    return 0;
  }
  if (cst < 0 or num < 0 or cst == 0 and num == 0) return 0;
  if (dp[i][num][cst] != -1) return dp[i][num][cst];
  long long ans = cst;
  ans = solve(i + 1, num, cst);
  for (long long j = (1); j <= (num); j++) {
    ans = max(ans, j * a[i] + solve(i + 1, num - j, cst + j * a[i]));
  }
  long long x = cst, cnt = 0;
  while (x - a[i] >= 0) {
    cnt++;
    x -= a[i];
    ans = max(ans, -cnt * a[i] + solve(i + 1, num + cnt, cst - (cnt * a[i])));
  }
  return dp[i][num][cst] = ans;
}
void MAIN() {
  cin >> n;
  for (long long i = (0); i <= (n - 1); i++) cin >> a[i];
  memset(dp, -1, sizeof(dp));
  cout << solve(0, 0, 1000) + 1000 << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long t = 1;
  while (t--) {
    MAIN();
  }
}
