n = int(input())

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

max_a = max(a)

second_a = sorted(a)[-2]

max_count = a.count(max_a) - 1

if max_count:

    [print(max_a) for _ in range(len(a))]

else:

    [print(max_a) if a[i] != max_a else print(second_a) for i in range(len(a))]

import sys



sr = lambda: sys.stdin.readline().rstrip()

ir = lambda: int(sr())

lr = lambda: list(map(int, sr().split()))



N = ir()

A = [ir() for _ in range(N)]

top = max(A)

if A.count(top) == 1:

    second = sorted(A, reverse=True)[1]

    for i in range(N):

        if A[i] == top:

            print(second)

        else:

            print(top)

else:

    for i in range(N):

        print(top)

# 23
n = int(input())
a = [int(input()) for i in range(n)]
max_a = max(a)
second_a = sorted(a)[-2]
max_count = a.count(max_a) - 1
if max_count:
    [print(max_a) for _ in range(len(a))]
else:
    [print(max_a) if a[i] != max_a else print(second_a) for i in range(len(a))]

import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N = ir()
A = [ir() for _ in range(N)]
top = max(A)
if A.count(top) == 1:
    second = sorted(A, reverse=True)[1]
    for i in range(N):
        if A[i] == top:
            print(second)
        else:
            print(top)
else:
    for i in range(N):
        print(top)
# 23

-n = int(input()) -a = [int(input()) for i in range(n)] -max_a = max(a) -second_a = sorted(a)[-2] -max_count = a.count(max_a) - 1 -if max_count: -    [print(max_a) for _ in range(len(a))] +import sys + +sr = lambda: sys.stdin.readline().rstrip() +ir = lambda: int(sr()) +lr = lambda: list(map(int, sr().split())) +N = ir() +A = [ir() for _ in range(N)] +top = max(A) +if A.count(top) == 1: +    second = sorted(A, reverse=True)[1] +    for i in range(N): +        if A[i] == top: +            print(second) +        else: +            print(top) -    [print(max_a) if a[i] != max_a else print(second_a) for i in range(len(a))] +    for i in range(N): +        print(top) +# 23