#include <bits/stdc++.h>
int main() {
  int N;
  std::cin >> N;
  std::vector<int> A(N);
  for (int i = 0; i < N; ++i) {
    std::cin >> A[i];
  }
  std::vector<int> max_from(N);
  int max_val = A.back();
  max_from[N - 1] = max_val;
  for (int i = N - 2; i >= 0; --i) {
    max_val = std::max(max_val, A[i]);
    max_from[i] = max_val;
  }
  std::vector<int> max_to(N);
  max_val = A.front();
  max_to[0] = max_val;
  for (int i = 1; i < N; ++i) {
    max_val = std::max(max_val, A[i]);
    max_to[i] = max_val;
  }
  for (int i = 0; i < N; ++i) {
    if (i == 0) {
      max_val = max_to[1];
    } else if (i == N - 1) {
      max_val = max_to[N - 2];
    } else {
      max_val = std::max(max_to[i - 1], max_from[i + 1]);
    }
    std::cout << max_val << std::endl;
  }
}
