#include <bits/stdc++.h>

#define rep(i,n) for (int i=0; i<(n); i++)
#define repr(i,n) for (int i=(n)-1; i>=0; i--)

using namespace std;
using ll = long long;

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  
  vector<int> L(n+1,-1e9) , R(n+1,-1e9);
  rep(i,n) L[i+1] = max(L[i].a[i]);
  repr(i,n) R[i] = max(R[i+1],a[i]);
  rep(i,n){
    cout << max(L[i], R[i+1]) << '\n';
    
  }
}