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