#include <bits/stdc++.h>
using namespace std;
long long int n;
long long int a[10000];
long long int ans = 0;
long long int dp[30000][100][81];
long long int fun(long long int curs, long long int curm, long long int i) {
  if (dp[curm][curs][i] != -1) {
    ans = max(ans, dp[curm][curs][i]);
    return 0;
  }
  ans = max(ans, curm);
  if (curm < 0 || i >= n || curs < 0) {
    return 0;
  }
  long long int z = curm;
  long long int k1 = fun(curs, curm, i + 1);
  long long int stock = a[i];
  long long int cnt = 1;
  while (z >= cnt * stock) {
    fun(curs + cnt, z - stock * cnt, i + 1);
    cnt++;
  }
  cnt = 1;
  while (cnt <= curs) {
    fun(curs - cnt, z + cnt * stock, i + 1);
    cnt++;
  }
  if (dp[curm][curs][i] == -1) {
    dp[curm][curs][i] = ans;
  }
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n;
  memset(dp, -1, sizeof dp);
  for (long long int i = 0; i < n; i++) cin >> a[i];
  fun(0, 1000, 0);
  cout << ans << "\n";
}
