#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
int n, a[82], dp[82][82][17000];
int f(int i, int s, int m) {
  if (i == n) return m;
  if (dp[i][s][m] == -1) {
    int x = 0, y = 0, z = f(i + 1, s, m);
    for (int j = 1; j * a[i] <= m; j++)
      x = max(x, f(i + 1, s + j, m - j * a[i]));
    for (int j = 1; j <= s; j++) y = max(y, f(i + 1, s - j, m + j * a[i]));
    dp[i][s][m] = max({x, y, z});
  }
  return dp[i][s][m];
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  memset(dp, -1, sizeof(dp));
  printf("%d\n", f(0, 0, 1000));
  return 0;
}
