#include<bits/stdc++.h>
using namespace std;
int n,a[200001],b[200001];
bool cmp(int x,int y){
	return x>y;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		b[i]=a[i];
	}
	sort(b+1,b+n+1,cmp);
	for(int i=1;i<=n;i++){
		if(a[i]==b[1]){
			printf("%d\n",b[2]);
		}else{
			printf("%d\n",b[1]);
		}
	}
}