#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;
const long long int INF = 1e18;
const long long int N = 1e6 + 1;
vector<long long int> g[N];
vector<long long int> vis(N);
vector<long long int> a;
long long int n;
long long int dp[81][10000][100];
long long int dfs(long long int pos, long long int amount,
                  long long int stocks) {
  if (pos == n) {
    return amount;
  }
  long long int &ans = dp[pos][amount][stocks];
  if (ans != -1) {
    return ans;
  }
  for (long long int i = 0; i <= stocks; i++) {
    ans = max(ans, dfs(pos + 1, amount + i * a[pos], stocks - i));
  }
  for (long long int i = amount, cnt = 0; i >= 0; i -= a[pos], cnt++) {
    ans = max(ans, dfs(pos + 1, i, stocks + cnt));
  }
  return ans;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int tc = 1;
  while (tc--) {
    cin >> n;
    a.resize(n);
    memset(dp, -1, sizeof(dp));
    for (long long int &it : a) {
      cin >> it;
    }
    cout << dfs(0, 1000, 0) << '\n';
  }
}
