#include <bits/stdc++.h>
using namespace std;
std::vector<long long> v;
long long dp[81][20][5000];
long long get(long long id, long long s, long long m) {
  if (m < 0 || s < 0) return INT_MIN;
  if (id == v.size() - 1) return m + s * v[id];
  if (dp[id][s][m] != -1) return dp[id][s][m];
  long long ans = INT_MIN;
  for (int i = 0; i <= m / v[id]; i++)
    ans = max(ans, get(id + 1, s + i, m - i * v[id]));
  for (int j = 0; j <= s; j++)
    ans = max(ans, get(id + 1, s - j, m + j * v[id]));
  return dp[id][s][m] = ans;
}
void solve() {
  long long n;
  cin >> n;
  v.resize(n);
  for (auto &i : v) cin >> i;
  memset(dp, -1, sizeof dp);
  cout << get(0, 0, 1000);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int TESTS = 1;
  while (TESTS--) {
    solve();
  }
  return 0;
}
