#include<bits/stdc++.h>
using namespace std;
int main(){
	int max1=0,max2=0,n,p[200005]={-1};
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>p[i];
		if(p[i]>p[max1]) max1=i;
		else if(p[i]<=p[max1]&&p[i]>p[max2]) max2=i;
	}
	for(int i=1;i<=n;i++){
		if(i==max1) cout<<p[max2]<<endl;
		else cout<<p[max1]<<endl;
	}
	return 0;
}
