N = int(eval(input()))

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

B = sorted(A,key=lambda x:x[1],reverse=True)

cnt = 0

bmax = B[0][1]

for i in range(N):

    if B[i][1]==bmax:

        cnt += 1

    else:break

for i in range(N):

    if A[i][1] < bmax:

        print(bmax)

    elif A[i][1]==bmax and cnt==1:

        print((B[1][1]))

    elif A[i][1]==bmax and cnt>1:

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

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

B = sorted(A,reverse=True)

b0 = B[0]

b1 = B[1]

for i in range(N):

    a = A[i]

    if a!=b0:

        print(b0)

    else:

        print(b1)
N = int(eval(input()))
A = [(i, int(eval(input()))) for i in range(N)]
B = sorted(A, key=lambda x: x[1], reverse=True)
cnt = 0
bmax = B[0][1]
for i in range(N):
    if B[i][1] == bmax:
        cnt += 1
    else:
        break
for i in range(N):
    if A[i][1] < bmax:
        print(bmax)
    elif A[i][1] == bmax and cnt == 1:
        print((B[1][1]))
    elif A[i][1] == bmax and cnt > 1:
        print(bmax)

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

-A = [(i, int(eval(input()))) for i in range(N)] -B = sorted(A, key=lambda x: x[1], reverse=True) -cnt = 0 -bmax = B[0][1] +A = [int(eval(input())) for _ in range(N)] +B = sorted(A, reverse=True) +b0 = B[0] +b1 = B[1] -    if B[i][1] == bmax: -        cnt += 1 +    a = A[i] +    if a != b0: +        print(b0) -        break -for i in range(N): -    if A[i][1] < bmax: -        print(bmax) -    elif A[i][1] == bmax and cnt == 1: -        print((B[1][1])) -    elif A[i][1] == bmax and cnt > 1: -        print(bmax) +        print(b1)