#include <bits/stdc++.h>
using namespace std;
const int sz = 85;
int n, a[sz], dp[sz][15][1005];
int fnc(int pos, int stock, int cash) {
  if (pos > n) return cash;
  int &w = dp[pos][stock][cash];
  if (w < 0) {
    w = cash;
    for (int i = 0; i <= stock; i++) {
      int nst = stock - i, ncsh = cash + i * a[pos];
      w = max(w, fnc(pos + 1, nst, ncsh));
    }
    for (int i = 1;; i++) {
      int spend = i * a[pos];
      if (spend > cash) break;
      int nst = stock + i, ncsh = cash - spend;
      w = max(w, fnc(pos + 1, nst, ncsh));
    }
  }
  return w;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  memset(dp, -1, sizeof(dp));
  cout << fnc(1, 0, 1000) << endl;
}
