#include<bits/stdc++.h>
using namespace std;
int main()
{
	
	int n,i,m1,m2;
	cin>>n;
	int a[n+1],b[n+1];
	for(i=1;i<=n;i++)
	{
		cin>>a[i];b[i]=a[i];
	}
	sort(a+1,a+n+1);
	m1=a[n];m2=a[n-1];
	
	for(i=1;i<=n;i++)
	{
		if(b[i]!=m1)
		cout<<m1<<endl;
		else
		cout<<m2<<endl;
	}
	return 0;
}
