N = int(eval(input()))



one = (0, 0)

two = (0, 0)

for i in range(N):

    A = int(eval(input()))

    if A > one[0]:

        two = one

        one = (A, i)

    elif A > two[0]:

        two = (A, i)



for i in range(N):

    if i == one[1]:

        print((two[0]))

    else:

        print((one[0]))

import sys



N = int(eval(input()))



one = (0, 0)

two = (0, 0)

for i, A in enumerate(map(int, sys.stdin.readlines())):

    if A > one[0]:

        two = one

        one = (A, i)

    elif A > two[0]:

        two = (A, i)



for i in range(N):

    if i == one[1]:

        print((two[0]))

    else:

        print((one[0]))

N = int(eval(input()))
one = (0, 0)
two = (0, 0)
for i in range(N):
    A = int(eval(input()))
    if A > one[0]:
        two = one
        one = (A, i)
    elif A > two[0]:
        two = (A, i)
for i in range(N):
    if i == one[1]:
        print((two[0]))
    else:
        print((one[0]))

import sys

N = int(eval(input()))
one = (0, 0)
two = (0, 0)
for i, A in enumerate(map(int, sys.stdin.readlines())):
    if A > one[0]:
        two = one
        one = (A, i)
    elif A > two[0]:
        two = (A, i)
for i in range(N):
    if i == one[1]:
        print((two[0]))
    else:
        print((one[0]))

+import sys + -for i in range(N): -    A = int(eval(input())) +for i, A in enumerate(map(int, sys.stdin.readlines())):