#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<string>
#include<stdexcept>
#include<stdio.h>
#include<queue>
#include <cmath>
#include<bits/stdc++.h>
//for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<n;i++) cin >> x[i];
#define pi pair<int,int> 
using namespace std;
using ll = long long;
int main(){
    int n; cin >> n;
    int a[n]; 
    int ma[n+2]={0},mb[n+2]={0};
    for(int i=0;i<n;i++){
        cin >> a[i]; 
        ma[i]=max(ma[i-1],a[i]);
    }
    for(int i=n-1;i>=0;i--){
        mb[i]=max(mb[i-1],a[i]);
    }
    for(int i=0;i<n;i++){
        cout << max(ma[i-1],mb[n-i-2]) << endl;
    }
    return 0;
}
