n=int(eval(input()))



L=[]

for i in range(n):

      L.append(int(eval(input())))

L2=sorted(L)

for i in range(n):

      if L[i]==L2[-1]:

            print((L2[-2]))

      else:

            print((L2[-1]))
n=int(eval(input()))

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

b=sorted(a)

m1=b[-1]

m2=b[-2]



for i in range(n):

    if a[i]==m1:

        print(m2)

    else:

        print(m1)

n = int(eval(input()))
L = []
for i in range(n):
    L.append(int(eval(input())))
L2 = sorted(L)
for i in range(n):
    if L[i] == L2[-1]:
        print((L2[-2]))
    else:
        print((L2[-1]))

n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
b = sorted(a)
m1 = b[-1]
m2 = b[-2]
for i in range(n):
    if a[i] == m1:
        print(m2)
    else:
        print(m1)

-L = [] +a = [int(eval(input())) for _ in range(n)] +b = sorted(a) +m1 = b[-1] +m2 = b[-2] -    L.append(int(eval(input()))) -L2 = sorted(L) -for i in range(n): -    if L[i] == L2[-1]: -        print((L2[-2])) +    if a[i] == m1: +        print(m2) -        print((L2[-1])) +        print(m1)