#include <bits/stdc++.h>
const double pi = 4 * atan(1);
using namespace std;
const long long MOD = 1000000007;
const int MAXN = 200005;
int num[100];
bool canBuy[100];
int n;
map<pair<int, pair<int, int>>, int> dp;
int solve(int idx, int stocks, int money) {
  if (idx == n) {
    return money;
  }
  pair<int, pair<int, int>> p = {idx, {stocks, money}};
  if (dp.count(p)) {
    return dp[p];
  }
  int ans = solve(idx + 1, stocks, money);
  if (canBuy[idx]) {
    for (int i = 1; num[idx] * i <= money; i++) {
      ans = max(ans, solve(idx + 1, stocks + i, money - num[idx] * i));
    }
    for (int i = 1; i <= stocks; i++) {
      ans = max(ans, solve(idx + 1, stocks - i, money + num[idx] * i));
    }
  } else {
    ans = max(ans, solve(idx + 1, 0, money + num[idx] * stocks));
  }
  return dp[p] = ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (long long i = (0); (i) < (n); ++i) {
    cin >> num[i];
  }
  for (int i = 0; i < n; i++) {
    canBuy[i] = false;
    for (int j = i + 1; j < n; j++) {
      canBuy[i] |= num[i] < num[j];
    }
  }
  cout << solve(0, 0, 1000) << "\n";
}
