#include <bits/stdc++.h>
using namespace std;
long long dp[80][2002][22];
int n;
long long a[100];
long long run(int idx, int m, int s) {
  if (dp[idx][m][s] != -1) return dp[idx][m][s];
  if (idx == n) return m;
  long long ans = m;
  for (int i = 0; i <= s; i++) {
    ans = max(ans, run(idx + 1, m + i * a[idx], s - i));
  }
  for (int i = 0;; i++) {
    if (m - i * a[idx] >= 0) {
      ans = max(ans, run(idx + 1, m - i * a[idx], s + i));
    } else
      break;
  }
  return dp[idx][m][s] = ans;
}
int main() {
  memset(dp, -1, sizeof dp);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  cout << run(0, 1000, 0);
}
