#include<iostream>
#include<algoriTHm>
#include<cstring>
using namespace std;
int n,x,minn,maxx;
int a[200005];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
	  scanf("%d",&a[i]);
	  if(a[i]>maxx) maxx=a[i];
	  else minn=max(minn,a[i]);
	}
	for(int i=1;i<=n;i++)
	  if(a[i]==maxx) printf("%d\n",minn);
	  else printf("%d\n",maxx);
	return 0;
	
}