#include<bits/stdc++.h>
using namespace std;
#define M 200005
int a[M],mx1[M],mx2[M];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%d",&a[i]);
	for(int i=1;i<=n;++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]));
}