#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int n; cin>>n;
	int a[n]; rep(i,n) cin>>a[i];
	int lm[n]={},rm[n]={};
	lm[0] = a[0];
	rm[n-1] = a[n-1];
	rep(i,n) lm[i] = max(lm[i-1],a[i]);
	rep(i,n) rm[n-1-i] = max(rm[n-i],a[n-1-i]);
	// rep(i,n) cout<<lm[i]<<" ";
	// rep(i,n) cout<<rm[i]<<" ";
	rep(i,n){
		int lmax=(i-1>=0?lm[i-1]:0);
		int rmax=(i+1<n?rm[i+1]:0);
		cout<<max(lmax,rmax)<<endl;
	}
	return 0;
}