#include <bits/stdc++.h>
using namespace std;
const int ss = 3e5 + 5;
long long ar[84], dp[82][5005][51], n;
long long f(int idx, int cur, int st) {
  if (idx == n) return cur;
  long long &res = dp[idx][cur][st];
  if (res != -1) return res;
  res = f(idx + 1, cur, st);
  if (st) {
    for (int i = 0; i <= st; i++) {
      res = max(res, f(idx + 1, cur + i * ar[idx], st - i));
    }
  } else {
    for (int i = 0; i * ar[idx] <= cur; i++) {
      res = max(res, f(idx + 1, cur - i * ar[idx], st + i));
    }
  }
  return res;
}
int main() {
  int t = 1;
  while (t--) {
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> ar[i];
    }
    for (int i = 0; i <= n; i++) {
      for (int j = 0; j <= 5000; j++) {
        for (int k = 0; k <= 50; k++) {
          dp[i][j][k] = -1;
        }
      }
    }
    cout << f(0, 1000, 0) << endl;
  }
  return 0;
}
