#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5, INF = 1E9 + 7;
long double EPS = 1e-9;
inline long long add(long long x, long long y) {
  x += y;
  if (x >= 1000000007) x -= 1000000007;
  return x;
}
inline long long sub(int x, int y) {
  x -= y;
  if (x < 0) x += 1000000007;
  return x;
}
inline long long mul(long long x, long long y) {
  return (x % 1000000007 * 1ll * y % 1000000007) % 1000000007;
}
inline long long pwr(long long a, long long b) {
  long long x = 1 % 1000000007;
  while (b) {
    if (b & 1) x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x % 1000000007;
}
inline long long inv(long long a) {
  return pwr(a, 1000000007 - 2) % 1000000007;
}
long long gcd(long long a, long long b) {
  if (!a) return b % 1000000007;
  return gcd(b % a, a) % 1000000007;
}
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
vector<int> v;
int dp[81][10005][100];
int ans = 0;
int recur(int day, int currentammount, int stocks) {
  if (day == (int)(v).size()) {
    ans = max(ans, currentammount);
    return 0;
  }
  int x = 0;
  int ans = 0, ans1 = 0;
  if (dp[day][currentammount][stocks] != -1)
    return dp[day][currentammount][stocks];
  while (currentammount - x * v[day] >= 0) {
    ans = max(ans, recur(day + 1, currentammount - x * v[day], stocks + x));
    x++;
  }
  x = 0;
  while (stocks - x >= 0) {
    ans1 = max(ans, recur(day + 1, currentammount + x * v[day], stocks - x));
    x++;
  }
  return dp[day][currentammount][stocks] = max(ans, ans1);
}
void solve() {
  int n;
  cin >> n;
  v.resize(n);
  for (auto& it : v) cin >> it;
  ;
  memset(dp, -1, sizeof(dp));
  recur(0, 1000, 0);
  cout << ans << "\n";
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int tc;
  tc = 1;
  while (tc--) {
    solve();
  }
}
