#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < a.size(); i++) {
    cin >> a[i];
  }
  bool is_rise = false;
  vector<pair<int, bool>> wave(0);
  for (int i = 1; i < n; i++) {
    if (!is_rise) {
      if (a[i - 1] < a[i]) {
        wave.push_back(pair<int, bool>(a[i - 1], true));
        is_rise = true;
        cout << i << endl;
      }
    } else {
      if (a[i - 1] > a[i]) {
        wave.push_back(pair<int, bool>(a[i - 1], false));
        is_rise = false;
        cout << i << endl;
      }
    }
  }
  if (wave.empty()) {
    cout << 1000;
    return 0;
  }
  if (wave.back().first < a[n - 1] || wave.back().second == true) {
    wave.push_back(pair<int, bool>(a[n - 1], false));
  }
  for (auto i : wave) {
    cout << i.first << " " << i.second << endl;
  }
  vector<pair<int, int>> dp(wave.size() + 1, pair<int, int>(1000, 0));
  for (int i = 0; i <= wave.size() - 2; i++) {
    if (i % 2 == 0) {
      (dp[i + 2].first = max((dp[i + 2].first), ((dp[i].first % wave[i].first) +
                                                 (dp[i].first / wave[i].first) *
                                                     wave[i + 1].first)));
    }
  }
  cout << dp.back().first << endl;
  return 0;
}
