#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < (int)(n); i++) cin >> a[i];
  vector<int> l(n), r(n);
  l[0] = a[0];
  r[n - 1] = a[n - 1];
  for (int i = 1; i < n; i++) {
    int w1 = l[i - 1];
    int w2 = a[i];
    l[i] = max(w1, w2);
    int w3 = l[n - i];
    int w4 = a[n - i - 1];
    r[n - i - 1] = max(w3, w4);
  }
  cout << r[1] << endl;
  for (int i = 0; i < (int)(n - 1); i++) {
    if (i == 0)
      continue;
    else
      cout << max(l[i - 1], r[i + 1]) << endl;
  }
  cout << l[n - 2] << endl;
}
