#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> data(0, 0), A(0, 0), B(0, 0);
  int x = 0;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    x = max(x, a);
    data.push_back(a);
    A.push_back(x);
  }
  x = 0;
  for (int i = N - 1; i >= 0; i--) {
    x = max(x, data[i]);
    B.push_back(x);
  }
  for (int i = 0; i < N; i++) {
    if (i == 0)
      cout << B[N - 1] << endl;
    else if (i == N - 1)
      cout << A[i] << endl;
    else {
      int a;
      a = max(A[i - 1], B[N - 2 - i]);
      cout << a << endl;
    }
  }
}
