#include <bits/stdc++.h>
using namespace std;
const long long int hell = (long long int)(1e18 + 100LL);
const double pi = acos(-1.0);
long long int dp[82][82][9000];
long long int ff(long long int ind, long long int stock, long long int sum,
                 vector<long long int>& ar, long long int n) {
  if (ind == n) {
    return sum;
  }
  if (dp[ind][stock][sum] != -1) return dp[ind][stock][sum];
  long long int ans = ff(ind + 1, stock, sum, ar, n);
  for (long long int i = 1; i <= stock; i++) {
    ans = max(ans, ff(ind + 1, stock - i, sum + ar[ind] * i, ar, n));
  }
  long long int x = sum / ar[ind];
  for (long long int i = 1; i <= x; i++) {
    ans = max(ans, ff(ind + 1, stock + i, sum - ar[ind] * i, ar, n));
  }
  dp[ind][stock][sum] = ans;
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int t, i, j, k, m, n, x, y;
  t = 1;
  while (t--) {
    long long int flag = 0, K;
    cin >> n;
    vector<long long int> ar(n);
    for (i = 0; i < n; i++) {
      cin >> ar[i];
    }
    memset(dp, -1, sizeof(dp));
    long long int ans = ff(0, 0, 1000, ar, n);
    cout << ans;
  }
  return 0;
}
