#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  int lm = v[0];
  vector<int> v1(n);
  for (int i = 0; i < n; i++) {
    lm = max(lm, v[i]);
    v1[i] = lm;
  }
  int rm = v[n - 1];
  vector<int> v2(n);
  for (int i = 0; i < n; i++) {
    rm = max(rm, v[n - i - 1]);
    v2[i] = rm;
  }
  cout << v2[n - 2] << endl;
  for (int i = 0; i < n - 2; i++) {
    cout << max(v1[i], v2[i]) << endl;
  }
  cout << v1[n - 2] << endl;
  return 0;
}
