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