N = int(eval(input()))

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



mls = [-1 for _ in range(N+1)]

for i, a in enumerate(A, 1):

    mls[i] = max(mls[i-1], a)



mrs = [-1 for _ in range(N+1)]

for i, a in enumerate(A[::-1], 1):

    mrs[i] = max(mrs[i-1], a)

mrs = mrs[::-1]



for i in range(N):

    print((max(mls[i], mrs[i+1])))

N = int(eval(input()))

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



m1, m2 = sorted(A, reverse=True)[0:2]

for a in A:

    print((m2 if a == m1 else m1))
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
mls = [-1 for _ in range(N + 1)]
for i, a in enumerate(A, 1):
    mls[i] = max(mls[i - 1], a)
mrs = [-1 for _ in range(N + 1)]
for i, a in enumerate(A[::-1], 1):
    mrs[i] = max(mrs[i - 1], a)
mrs = mrs[::-1]
for i in range(N):
    print((max(mls[i], mrs[i + 1])))

N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
m1, m2 = sorted(A, reverse=True)[0:2]
for a in A:
    print((m2 if a == m1 else m1))

-mls = [-1 for _ in range(N + 1)] -for i, a in enumerate(A, 1): -    mls[i] = max(mls[i - 1], a) -mrs = [-1 for _ in range(N + 1)] -for i, a in enumerate(A[::-1], 1): -    mrs[i] = max(mrs[i - 1], a) -mrs = mrs[::-1] -for i in range(N): -    print((max(mls[i], mrs[i + 1]))) +m1, m2 = sorted(A, reverse=True)[0:2] +for a in A: +    print((m2 if a == m1 else m1))