#include <bits/stdc++.h>
using namespace std;
int ara[100];
int n;
int dp[17005][85][200];
int f(int taka, int now, int koyta) {
  if (now > n) return taka;
  int &ans = dp[taka][now][koyta];
  if (ans != -1) return ans;
  for (int i = 0; taka - i * ara[now] >= 0; i++)
    ans = max(ans, f(taka - i * ara[now], now + 1, koyta + i));
  for (int i = 0; i <= koyta; i++)
    ans = max(ans, f(taka + i * ara[now], now + 1, koyta - i));
  return ans;
}
void solve() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> ara[i];
  memset(dp, -1, sizeof dp);
  cout << f(1000, 1, 0);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int testcase = 1;
  for (int i = 1; i <= testcase; i++) {
    solve();
  }
  return 0;
}
