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