n = int(eval(input()))

l = []

for i in range(n):

    l.append(int(eval(input())))



l_b = sorted(l)

max_a = l_b[-1]

max_b = l_b[-2]



for j in range(len(l)):

    if max_a == l[j]:

        print(max_b)

    else:

        print(max_a)

N, *l = list(map(int, open(0).read().split()))



l_b = sorted(l)

max_a = l_b[-1]

max_b = l_b[-2]



for j in range(N):

    if max_a == l[j]:

        print(max_b)

    else:

        print(max_a)

n = int(eval(input()))
l = []
for i in range(n):
    l.append(int(eval(input())))
l_b = sorted(l)
max_a = l_b[-1]
max_b = l_b[-2]
for j in range(len(l)):
    if max_a == l[j]:
        print(max_b)
    else:
        print(max_a)

N, *l = list(map(int, open(0).read().split()))
l_b = sorted(l)
max_a = l_b[-1]
max_b = l_b[-2]
for j in range(N):
    if max_a == l[j]:
        print(max_b)
    else:
        print(max_a)

-n = int(eval(input())) -l = [] -for i in range(n): -    l.append(int(eval(input()))) +N, *l = list(map(int, open(0).read().split())) -for j in range(len(l)): +for j in range(N):