#include <bits/stdc++.h>
using namespace std;
const int N = 3e6 + 7, M = 1000000007, inf = INT_MAX;
const long long INF = LLONG_MAX;
int dp[81][1000][3000], arr[82], n;
int ans(int id, int total, int cash) {
  if (id == n - 1) return total * arr[id] + cash;
  int &mafia = dp[id][total][cash];
  if (mafia != -1) return mafia;
  int res = 0;
  for (int i = 0; i < (int)total + 1; i++) {
    int a1 = ans(id + 1, total - i, cash + i * arr[id]);
    res = max(a1, res);
  }
  int cnt = 1;
  while (cnt * arr[id] <= cash) {
    int a1 = ans(id + 1, total + cnt, cash - cnt * arr[id]);
    cnt++;
    res = max(res, a1);
  }
  return mafia = res;
}
void solve() {
  memset(dp, -1, sizeof dp);
  cin >> n;
  for (int i = 0; i < (int)n; i++) cin >> arr[i];
  int res = ans(0, 0, 1000);
  cout << res << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int test = 1;
  while (test--) solve();
}
