#import <Foundation/Foundation.h>
typedef long long Int;
int main() {
	Int N;
	scanf("%lld",&N);
	Int *A = (Int*)malloc(N*sizeof(Int));
	Int *L = (Int*)malloc(N*sizeof(Int));
	for(Int i=0;i<N;i++){
		scanf("%lld",A+i);
		if(i==0) L[i] = A[i];
		else L[i] = MAX(L[i-1],A[i]);
	}
	Int *R = (Int*)malloc(N*sizeof(Int));
	for(Int i=N-1;i>=0;i--){
		if(i==N-1) R[i] = A[i];
		else R[i] = MAX(R[i+1],A[i]);
	}
	for(Int i=0;i<N;i++){
		printf("%lld\n", i==0 ? R[1] : i==N-1 ? L[N-2] : MAX(L[i-1],R[i+1]));
	}
}