#include <bits/stdc++.h>
using namespace std;
long long INF = 1 << 28;
const double PI = acos(-1.0);
int dir[4][2] = {1, 0, -1, 0, 0, -1, 0, 1};
int knight[8][2] = {1, 2, 1, -2, 2, 1, 2, -1, -1, 2, -1, -2, -2, 1, -2, -1};
const long double EPS = 1e-7;
struct compare {
  bool operator()(const pair<int, pair<int, int> >& l,
                  const pair<int, pair<int, int> >& r) {
    if (l.first == r.first) {
      return l.second.first > r.second.first;
    }
    return l.first < r.first;
  }
};
const int mx = 500150;
int mod = 1000000007;
int arr[mx];
int dp[85][30][5000];
int n;
int flag = 0;
int fun(int pos, int kinsi, int val) {
  if (kinsi >= 30 || val >= 5000) {
    flag = 1;
    return 0;
  }
  if (pos == n) {
    return val;
  }
  int& ret = dp[pos][kinsi][val];
  if (ret != -1) {
    return ret;
  }
  int k = val / arr[pos];
  ret = 0;
  ret = max(ret, fun(pos + 1, kinsi, val));
  int sum = 0;
  for (int i = 1; i <= k; i++) {
    sum += arr[pos];
    ret = max(ret, fun(pos + 1, kinsi + i, val - sum));
  }
  sum = 0;
  for (int i = 1; i <= kinsi; i++) {
    sum += arr[pos];
    ret = max(ret, fun(pos + 1, kinsi - i, val + sum));
  }
  return ret;
}
int main() {
  memset(dp, -1, sizeof(dp));
  int t, tc = 1;
  t = 1;
  while (t--) {
    int k;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
      scanf("%d", &arr[i]);
    }
    cout << fun(0, 0, 1000) << endl;
  }
  return 0;
}
