#include<bits/stdc++.h>
#define M 200005
using namespace std;
int a[M],mx1,mx2,n;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		if(a[i]>=mx1)mx2=mx1,mx1=a[i];
		else if(a[i]>=mx2)mx2=a[i];
	} 
	for(int i=1;i<=n;i++){
		if(a[i]==mx1)printf("%d\n",mx2);
		else printf("%d\n",mx1);
	}
	return 0;
}