#include<bits/stdc++.h>
using namespace std;
int n,A[1000010],num[1000010];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&A[i]),num[i]=A[i];
	sort(A+1,A+1+n);
	for(int i=1;i<=n;i++){
		if(num[i]!=A[n])printf("%d\n",A[n]);
		else printf("%d\n",A[n-1]);
	}
	return 0;
}