#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < (N); ++i) {
    cin >> A.at(i);
  }
  vector<int> right(N);
  vector<int> left(N);
  for (int i = 1; i < N; i++) left.at(i) = max(left.at(i - 1), A.at(i - 1));
  for (int i = N - 2; i >= 0; i--) right.at(i) = max(right.at(i + 1), A.at(i));
  for (int i = 0; i < (N); ++i) cout << max(left.at(i), right.at(i)) << endl;
  return 0;
}
