N = int(eval(input()))

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

max_a = max(A)

count = A.count(max_a)



if count > 1:

    for n in range(N):

        print(max_a)

else:

    for n in range(N):

        if A[n] == max_a:

            print((max(A[:n] + A[n+1:])))

            continue

        print(max_a)
N = int(eval(input()))

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

B = sorted(A, reverse=True)

for a in A:

    if a == B[0]:

        print((B[1]))

    else:

        print((B[0]))
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
max_a = max(A)
count = A.count(max_a)
if count > 1:
    for n in range(N):
        print(max_a)
else:
    for n in range(N):
        if A[n] == max_a:
            print((max(A[:n] + A[n + 1 :])))
            continue
        print(max_a)

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

-max_a = max(A) -count = A.count(max_a) -if count > 1: -    for n in range(N): -        print(max_a) -else: -    for n in range(N): -        if A[n] == max_a: -            print((max(A[:n] + A[n + 1 :]))) -            continue -        print(max_a) +B = sorted(A, reverse=True) +for a in A: +    if a == B[0]: +        print((B[1])) +    else: +        print((B[0]))