N=int(eval(input()))

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

m=max(A)

n=sorted(A,reverse=True)[1]

for i in range(N):

    if A[i]<m:

        print(m)

    else:

        print(n)

N=int(eval(input()))

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

m=max(A)

n=sorted(A,reverse=True)[1]

print(("\n".join([str(m) if a<m else str(n) for a in A])))

N = int(eval(input()))
A = [int(eval(input())) for n in range(N)]
m = max(A)
n = sorted(A, reverse=True)[1]
for i in range(N):
    if A[i] < m:
        print(m)
    else:
        print(n)

N = int(eval(input()))
A = [int(eval(input())) for n in range(N)]
m = max(A)
n = sorted(A, reverse=True)[1]
print(("\n".join([str(m) if a < m else str(n) for a in A])))

-for i in range(N): -    if A[i] < m: -        print(m) -    else: -        print(n) +print(("\n".join([str(m) if a < m else str(n) for a in A])))