#include<iostream>
#include<algorithm>
using namespace std;
int n,a[200005],b[200005],o;
bool cmp(int x,int y){
	return x>y;
}
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		b[i]=a[i];
	}
	sort(b,b+n,cmp);
	for(int i=0;i<n;i++){
		if(a[i]<b[0]){
			cout<<b[0]<<endl;
		}
		else{
			cout<<b[1]<<endl;
		}
	}
}