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