#include<bits/stdc++.h>
using namespace std;

bool cmp(int a,int b){
	return a>b;
}

int main(){
	int n;
	cin>>n;
	
	int a[200005],b[200005];
	
	for(int i=1;i<=n;i++){
		cin>>a[i];
		b[i]=a[i];
	}
	
	sort(a+1,a+n+1,cmp);
	
	for(int i=1;i<=n;i++){
		if(b[i]==a[1]) cout<<a[2]<<endl;
		else cout<<a[1]<<endl;
	}
	return 0;
}