def main():

    N = int(eval(input()))

    A = [int(eval(input())) for i in range(N)]

    A_sort = sorted(A)

    if (A_sort[-1] == A_sort[-2]):

        for i in range(N):

            print((A_sort[-1]))

    else:

        for i in range(N):

            if(A[i]==A_sort[-1]):

                print((A_sort[-2]))

            else:

                print((A_sort[-1]))



main()

N = int(eval(input()))

x = [int(eval(input())) for i in range(N)]

x_sort = sorted(x, reverse=True)

for i in range(N):

    if x[i] == x_sort[0]:

        print((x_sort[1]))

    else:

        print((x_sort[0]))

def main():
    N = int(eval(input()))
    A = [int(eval(input())) for i in range(N)]
    A_sort = sorted(A)
    if A_sort[-1] == A_sort[-2]:
        for i in range(N):
            print((A_sort[-1]))
    else:
        for i in range(N):
            if A[i] == A_sort[-1]:
                print((A_sort[-2]))
            else:
                print((A_sort[-1]))


main()

N = int(eval(input()))
x = [int(eval(input())) for i in range(N)]
x_sort = sorted(x, reverse=True)
for i in range(N):
    if x[i] == x_sort[0]:
        print((x_sort[1]))
    else:
        print((x_sort[0]))

-def main(): -    N = int(eval(input())) -    A = [int(eval(input())) for i in range(N)] -    A_sort = sorted(A) -    if A_sort[-1] == A_sort[-2]: -        for i in range(N): -            print((A_sort[-1])) +N = int(eval(input())) +x = [int(eval(input())) for i in range(N)] +x_sort = sorted(x, reverse=True) +for i in range(N): +    if x[i] == x_sort[0]: +        print((x_sort[1])) -        for i in range(N): -            if A[i] == A_sort[-1]: -                print((A_sort[-2])) -            else: -                print((A_sort[-1])) - - -main() +        print((x_sort[0]))