#134



N = int(eval(input()))

A_max = 0

A_max_s = 0

flag = 0

A = []



for i in range(N):

    a = int(eval(input()))

    A.append(a)

    if a > A_max:

        A_max_s = A_max

        A_max = a

        ind_max = i

        flag = 0

    elif A_max_s < a < A_max:

        A_max_s = a

    elif a == A_max:

        flag += 1

        

if flag >= 1:

    for i in range(N):

        print(A_max)

elif flag == 0:

    for i in range(N):

        if i != ind_max:

            print(A_max)

        else:

            print(A_max_s)



    

    
N = int(eval(input()))

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

A_copy = A[:]

A_copy.sort()

# print(A, A_sort)

A_max = A_copy[len(A_copy)-1]

A_second = A_copy[len(A_copy)-2]

for i in range(N):

    if A[i] != A_max:

        print(A_max)

    else:

        print(A_second)
# 134
N = int(eval(input()))
A_max = 0
A_max_s = 0
flag = 0
A = []
for i in range(N):
    a = int(eval(input()))
    A.append(a)
    if a > A_max:
        A_max_s = A_max
        A_max = a
        ind_max = i
        flag = 0
    elif A_max_s < a < A_max:
        A_max_s = a
    elif a == A_max:
        flag += 1
if flag >= 1:
    for i in range(N):
        print(A_max)
elif flag == 0:
    for i in range(N):
        if i != ind_max:
            print(A_max)
        else:
            print(A_max_s)

N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
A_copy = A[:]
A_copy.sort()
# print(A, A_sort)
A_max = A_copy[len(A_copy) - 1]
A_second = A_copy[len(A_copy) - 2]
for i in range(N):
    if A[i] != A_max:
        print(A_max)
    else:
        print(A_second)

-# 134 -A_max = 0 -A_max_s = 0 -flag = 0 -A = [] +A = [int(eval(input())) for i in range(N)] +A_copy = A[:] +A_copy.sort() +# print(A, A_sort) +A_max = A_copy[len(A_copy) - 1] +A_second = A_copy[len(A_copy) - 2] -    a = int(eval(input())) -    A.append(a) -    if a > A_max: -        A_max_s = A_max -        A_max = a -        ind_max = i -        flag = 0 -    elif A_max_s < a < A_max: -        A_max_s = a -    elif a == A_max: -        flag += 1 -if flag >= 1: -    for i in range(N): +    if A[i] != A_max: -elif flag == 0: -    for i in range(N): -        if i != ind_max: -            print(A_max) -        else: -            print(A_max_s) +    else: +        print(A_second)