from collections import Counter



n = int(eval(input()))

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

al_s = sorted(al, reverse=True)

c = Counter(al_s)

ck = list(c.keys())

cv = list(c.values())





for a in al:

    if a == ck[0]:

        if cv[0] == 1:

            print((ck[1]))

        else:

            print((ck[0]))

    else:

        print((ck[0]))



n = int(eval(input()))

al = list(int(eval(input())) for _ in range(n))



al_s = sorted(al)

fir = al_s[-1]

sec = al_s[-2]



for a in al:

    if a == fir:

        print(sec)

    else:

        print(fir)

from collections import Counter

n = int(eval(input()))
al = [int(eval(input())) for _ in range(n)]
al_s = sorted(al, reverse=True)
c = Counter(al_s)
ck = list(c.keys())
cv = list(c.values())
for a in al:
    if a == ck[0]:
        if cv[0] == 1:
            print((ck[1]))
        else:
            print((ck[0]))
    else:
        print((ck[0]))

n = int(eval(input()))
al = list(int(eval(input())) for _ in range(n))
al_s = sorted(al)
fir = al_s[-1]
sec = al_s[-2]
for a in al:
    if a == fir:
        print(sec)
    else:
        print(fir)

-from collections import Counter - -al = [int(eval(input())) for _ in range(n)] -al_s = sorted(al, reverse=True) -c = Counter(al_s) -ck = list(c.keys()) -cv = list(c.values()) +al = list(int(eval(input())) for _ in range(n)) +al_s = sorted(al) +fir = al_s[-1] +sec = al_s[-2] -    if a == ck[0]: -        if cv[0] == 1: -            print((ck[1])) -        else: -            print((ck[0])) +    if a == fir: +        print(sec) -        print((ck[0])) +        print(fir)