#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> num;
int memo[100][16010][100];
int solve(int index, int rem, int stocks) {
  if (index == n) return rem;
  if (memo[index][rem][stocks] != -1) return memo[index][rem][stocks];
  int tot = rem, tot_stock = stocks;
  int ans = 0;
  ans = max(ans, solve(index + 1, rem, stocks));
  while (tot - num[index] >= 0) {
    tot = tot - num[index];
    tot_stock++;
    ans = max(ans, solve(index + 1, tot, tot_stock));
  }
  tot = rem;
  tot_stock = stocks;
  while (tot_stock - 1 >= 0) {
    tot_stock = tot_stock - 1;
    tot = tot + num[index];
    ans = max(ans, solve(index + 1, tot, tot_stock));
  }
  return memo[index][rem][stocks] = ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  num.assign(n, 0);
  memset(memo, -1, sizeof(memo));
  for (int i = 0; i < n; i++) {
    cin >> num[i];
  }
  int ans = solve(0, 1000, 0);
  cout << ans << endl;
  return 0;
}
