a=int(eval(input()))

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

m=max(b) 



if b.count(m)>=2:

    for i in range(a):

        print (m)

else:

    c=b.copy()

    c.sort(reverse=True)

    m2=c[1]

    for i in range(a):

        if b[i]==m:

            print(m2)

        else:

            print (m)

            



n = int(eval(input()))

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

maxa = max(a)

# print(maxa)

if a.count(maxa) == 1:

    b = sorted(a, reverse=True)



    maxa2 = b[1]

    for i in range(n):

        if a[i] == maxa:

            print(maxa2)

        else:

            print(maxa)



else:

    for i in range(n):

        print(maxa)

a = int(eval(input()))
b = [int(eval(input())) for i in range(a)]
m = max(b)
if b.count(m) >= 2:
    for i in range(a):
        print(m)
else:
    c = b.copy()
    c.sort(reverse=True)
    m2 = c[1]
    for i in range(a):
        if b[i] == m:
            print(m2)
        else:
            print(m)

n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
maxa = max(a)
# print(maxa)
if a.count(maxa) == 1:
    b = sorted(a, reverse=True)
    maxa2 = b[1]
    for i in range(n):
        if a[i] == maxa:
            print(maxa2)
        else:
            print(maxa)
else:
    for i in range(n):
        print(maxa)

-a = int(eval(input())) -b = [int(eval(input())) for i in range(a)] -m = max(b) -if b.count(m) >= 2: -    for i in range(a): -        print(m) +n = int(eval(input())) +a = [int(eval(input())) for _ in range(n)] +maxa = max(a) +# print(maxa) +if a.count(maxa) == 1: +    b = sorted(a, reverse=True) +    maxa2 = b[1] +    for i in range(n): +        if a[i] == maxa: +            print(maxa2) +        else: +            print(maxa) -    c = b.copy() -    c.sort(reverse=True) -    m2 = c[1] -    for i in range(a): -        if b[i] == m: -            print(m2) -        else: -            print(m) +    for i in range(n): +        print(maxa)