N = int(eval(input()))

A = list(int(eval(input())) for k in range(N))



mx, mxn = sorted(A, reverse=True)[:2]



for i in range(N):

    if A[i] == mx:

        print(mxn)

    else:

        print(mx)

N = int(eval(input()))

A = list(int(eval(input())) for k in range(N))



mx, mxn = sorted(A, reverse=True)[:2]



result = [mxn if x==mx else mx for x in A]

print(('\n'.join(map(str, result))))
N = int(eval(input()))
A = list(int(eval(input())) for k in range(N))
mx, mxn = sorted(A, reverse=True)[:2]
for i in range(N):
    if A[i] == mx:
        print(mxn)
    else:
        print(mx)

N = int(eval(input()))
A = list(int(eval(input())) for k in range(N))
mx, mxn = sorted(A, reverse=True)[:2]
result = [mxn if x == mx else mx for x in A]
print(("\n".join(map(str, result))))

-for i in range(N): -    if A[i] == mx: -        print(mxn) -    else: -        print(mx) +result = [mxn if x == mx else mx for x in A] +print(("\n".join(map(str, result))))