#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
using PII = pair<int, int>;
const int64 INF = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1000000007;
const int MAXN = 200005;
int64 a[MAXN];
int dp[85][2005][15];
int n;
int solve(int i, int m, int s) {
  if (i == n) return m + s * a[n];
  int &ans = dp[i][m][s];
  if (ans != -1) return ans;
  ans = 0;
  for (int j = 0; j <= s; j++) {
    ans = max(ans, solve(i + 1, m + j * a[i], s - j));
  }
  for (int j = 0; j * a[i] <= m; j++) {
    ans = max(ans, solve(i + 1, m - j * a[i], s + j));
  }
  return ans;
}
void run() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  memset(dp, -1, sizeof(dp));
  cout << solve(1, 1000, 0) << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  run();
}
