N=int(eval(input()))

A=[int(eval(input())) for i in range(N)]

LM=[0,A[0]]

a=A[::-1]

RM=[a[0]]

for i in range(1,N-1):

    LM.append(max(LM[-1],A[i]))

    RM.append(max(RM[-1],a[i]))

RM=RM[::-1]+[0]

for i in range(N):

    print((max(LM[i],RM[i])))
N=int(eval(input()))

A=[int(eval(input())) for i in range(N)]

M=A[::-1]

M.sort()

for i in A:

    if i==M[-1]:print((M[-2]))

    else:print((M[-1]))
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
LM = [0, A[0]]
a = A[::-1]
RM = [a[0]]
for i in range(1, N - 1):
    LM.append(max(LM[-1], A[i]))
    RM.append(max(RM[-1], a[i]))
RM = RM[::-1] + [0]
for i in range(N):
    print((max(LM[i], RM[i])))

N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
M = A[::-1]
M.sort()
for i in A:
    if i == M[-1]:
        print((M[-2]))
    else:
        print((M[-1]))

-LM = [0, A[0]] -a = A[::-1] -RM = [a[0]] -for i in range(1, N - 1): -    LM.append(max(LM[-1], A[i])) -    RM.append(max(RM[-1], a[i])) -RM = RM[::-1] + [0] -for i in range(N): -    print((max(LM[i], RM[i]))) +M = A[::-1] +M.sort() +for i in A: +    if i == M[-1]: +        print((M[-2])) +    else: +        print((M[-1]))