n = int(eval(input()))

l = []

for i in range(n):

    l.append([int(eval(input())), i])

l.sort(reverse=True)

m1 = l[0][0]

m2 = l[1][0]

id1 = l[0][1]

for i in range(n):

    if i == id1:

        print(m2)

    else:

        print(m1)

n = int(eval(input()))

l = []

m1 = 0

m2 = 0

for i in range(n):

    num = int(eval(input()))

    l.append(num)

    if num > m1:

        m1 = num

    elif num > m2:

        m2 = num



for i in range(n):

    if l[i] != m1:

        print(m1)

    else:

        print(m2)

n = int(eval(input()))
l = []
for i in range(n):
    l.append([int(eval(input())), i])
l.sort(reverse=True)
m1 = l[0][0]
m2 = l[1][0]
id1 = l[0][1]
for i in range(n):
    if i == id1:
        print(m2)
    else:
        print(m1)

n = int(eval(input()))
l = []
m1 = 0
m2 = 0
for i in range(n):
    num = int(eval(input()))
    l.append(num)
    if num > m1:
        m1 = num
    elif num > m2:
        m2 = num
for i in range(n):
    if l[i] != m1:
        print(m1)
    else:
        print(m2)

+m1 = 0 +m2 = 0 -    l.append([int(eval(input())), i]) -l.sort(reverse=True) -m1 = l[0][0] -m2 = l[1][0] -id1 = l[0][1] +    num = int(eval(input())) +    l.append(num) +    if num > m1: +        m1 = num +    elif num > m2: +        m2 = num -    if i == id1: +    if l[i] != m1: +        print(m1) +    else: -    else: -        print(m1)