#include <bits/stdc++.h>
using namespace std;
int main(int argc, char* argv[]) {
  {
    long long n = -1;
    cin >> n;
    if (n < 0) return 0;
    vector<long long> a(n + 2);
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
    }
    a[n] = a[n - 1];
    a[n + 1] = a[n - 1];
    vector<pair<pair<long long, long long>, pair<long long, long long> > > q;
    q.emplace_back(
        pair<pair<long long, long long>, pair<long long, long long> >(
            pair<long long, long long>(1000, 1000),
            pair<long long, long long>(0, 0)));
    for (int i = 0; i < n; ++i) {
      if (a[i] == a[i + 1]) continue;
      if (a[i] > a[i + 1] && a[i + 1] > a[i + 2]) continue;
      vector<pair<pair<long long, long long>, pair<long long, long long> > > nq;
      if (a[i] < a[i + 1]) {
        for (auto kv : q) {
          long long m = kv.first.second;
          if (m < a[i]) {
            nq.emplace_back(kv);
          } else {
            long long x = m / a[i];
            long long s = kv.second.first + x;
            m -= a[i] * x;
            nq.emplace_back(
                pair<pair<long long, long long>, pair<long long, long long> >(
                    pair<long long, long long>(s * a[i + 1] + m, m),
                    pair<long long, long long>(s, 0)));
            if (x > 1) {
              --s;
              m += a[i];
              nq.emplace_back(
                  pair<pair<long long, long long>, pair<long long, long long> >(
                      pair<long long, long long>(s * a[i + 1] + m, m),
                      pair<long long, long long>(s, 0)));
            }
          }
        }
      } else {
        for (auto kv : q) {
          long long m = kv.first.second + kv.second.first * a[i];
          nq.emplace_back(
              pair<pair<long long, long long>, pair<long long, long long> >(
                  pair<long long, long long>(m, m),
                  pair<long long, long long>(0, 0)));
        }
      }
      sort(nq.begin(), nq.end());
      nq.resize(unique(nq.begin(), nq.end()) - nq.begin());
      sort(nq.rbegin(), nq.rend());
      if (nq.size() > 100000) {
        nq.resize(100000);
      }
      q = nq;
    }
    long long ans = 0;
    for (auto kv : q) {
      long long m = kv.first.second + kv.second.first * a[n - 1];
      ans = max(ans, m);
    }
    cout << ans << endl;
  }
  return 0;
}
