N = int(eval(input()))

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



L = [0] * (200000+1)

R = [0] * (200000+1)



L[0] = 0

for i in range(1, N+1):

    L[i] = max(A[i-1], L[i-1])



R[N] = 0

for i in range(N-1, 0, -1):

    R[i] = max(R[i+1], A[i])



#print(L)

#print(R)



for i in range(N):

    ans = max(L[i], R[i+1])

    print(ans)


import sys

input = sys.stdin.readline

sys.setrecursionlimit(10**6)

##############################



N = int(eval(input()))

A = []

for i in range(N):

    a = int(eval(input()))

    A.append(a)



B = list(reversed(sorted(A)))



for i in range(N):

    # 最大か二番目を出せばいい

    if A[i] == B[0]:

        print((B[1]))

    else:

        print((B[0]))
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
L = [0] * (200000 + 1)
R = [0] * (200000 + 1)
L[0] = 0
for i in range(1, N + 1):
    L[i] = max(A[i - 1], L[i - 1])
R[N] = 0
for i in range(N - 1, 0, -1):
    R[i] = max(R[i + 1], A[i])
# print(L)
# print(R)
for i in range(N):
    ans = max(L[i], R[i + 1])
    print(ans)

import sys

input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################
N = int(eval(input()))
A = []
for i in range(N):
    a = int(eval(input()))
    A.append(a)
B = list(reversed(sorted(A)))
for i in range(N):
    # 最大か二番目を出せばいい
    if A[i] == B[0]:
        print((B[1]))
    else:
        print((B[0]))

+import sys + +input = sys.stdin.readline +sys.setrecursionlimit(10**6) +############################## -A = [int(eval(input())) for _ in range(N)] -L = [0] * (200000 + 1) -R = [0] * (200000 + 1) -L[0] = 0 -for i in range(1, N + 1): -    L[i] = max(A[i - 1], L[i - 1]) -R[N] = 0 -for i in range(N - 1, 0, -1): -    R[i] = max(R[i + 1], A[i]) -# print(L) -# print(R) +A = [] -    ans = max(L[i], R[i + 1]) -    print(ans) +    a = int(eval(input())) +    A.append(a) +B = list(reversed(sorted(A))) +for i in range(N): +    # 最大か二番目を出せばいい +    if A[i] == B[0]: +        print((B[1])) +    else: +        print((B[0]))