#include <bits/stdc++.h>
using namespace std;
const long long Mod = 1e9 + 7;
const long long max_n = 81;
long long n, a[max_n];
map<pair<long long, pair<long long, long long> >, long long> M;
long long f(long long i, long long yen, long long stocks) {
  if (i == n) return yen;
  if (M.find({i, {yen, stocks}}) != M.end()) return M[{i, {yen, stocks}}];
  long long ans = f(i + 1, yen, stocks);
  for (long long k = 1;; k++) {
    if (a[i] * k > yen) break;
    ans = max(ans, f(i + 1, yen - a[i] * k, stocks + k));
  }
  for (long long s = 1; s <= stocks; s++) {
    ans = max(ans, f(i + 1, yen + s * a[i], stocks - s));
  }
  M[{i, {yen, stocks}}] = ans;
  return ans;
}
signed main() {
  cin >> n;
  for (long long i = 0; i < 80; i++) cin >> a[i];
  cout << f(0, 1000, 0) << "\n";
}
