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