#include<bits/stdc++.h>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n + 1);
  for(int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  vector<int> b(n + 1), c(n + 2);
  for(int i = 1; i <= n; i++) {
    b[i] = max(a[i], b[i-1]);
  }
  for(int i = n; i; i--) {
    c[i] = max(a[i], c[i+1];
  }
  for(int i = 1; i <= n; i++) {
    cout << max(b[i-1], c[i+1]) << endl;
  }
}