n = int(eval(input()))

a = [int(eval(input())) for i in range(n)]

Amax = max(a)

Amax2 = sorted(a)[-2]

for i in range(n):

    if Amax > a[i]:

        print(Amax)

    else:

        print(Amax2)
n =  int(eval(input()))

A = []

for i in range(n):

    A.append(int(eval(input())))

ma = max(A)

ma2 = sorted(A)[-2]

for a in A:

    if a == ma:

        print(ma2)

    else:

        print(ma)
n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
Amax = max(a)
Amax2 = sorted(a)[-2]
for i in range(n):
    if Amax > a[i]:
        print(Amax)
    else:
        print(Amax2)

n = int(eval(input()))
A = []
for i in range(n):
    A.append(int(eval(input())))
ma = max(A)
ma2 = sorted(A)[-2]
for a in A:
    if a == ma:
        print(ma2)
    else:
        print(ma)

-a = [int(eval(input())) for i in range(n)] -Amax = max(a) -Amax2 = sorted(a)[-2] +A = [] -    if Amax > a[i]: -        print(Amax) +    A.append(int(eval(input()))) +ma = max(A) +ma2 = sorted(A)[-2] +for a in A: +    if a == ma: +        print(ma2) -        print(Amax2) +        print(ma)