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