import sys
input = sys.stdin.readline
N = int(input())
A = [int(input()) for _ in range(N)]
AL = [0] * (N+1)
AR = [0] * (N+1) 
for i in range(N):
    AL[i+1] = max(AL[i], A[i])
for i in range(N):
    AR[i] = max(AR[i+1], A[i])
for i in range(N):
    print(max(AL[i], AR[i+1]))