N = int(eval(input()))

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



L = [0] * (N+1)

R = [0] * (N+2)

A.append(0)



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

    if i == 1:

        L[1] = 0

        R[N+1] = 0

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

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



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

    print((max(L[i], R[i])))
N = int(eval(input()))

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



B = A.copy()

B.sort(key=lambda x:-x)



last = B[0]

second = B[1]



for num in A:

  if num != last:

    print(last)

  else:

    print(second)

N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
L = [0] * (N + 1)
R = [0] * (N + 2)
A.append(0)
for i in range(1, N + 1):
    if i == 1:
        L[1] = 0
        R[N + 1] = 0
    L[i] = max(L[i - 1], A[i - 2])
    R[N - i + 1] = max(R[N - i + 2], A[N - i + 1])
for i in range(1, N + 1):
    print((max(L[i], R[i])))

N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
B = A.copy()
B.sort(key=lambda x: -x)
last = B[0]
second = B[1]
for num in A:
    if num != last:
        print(last)
    else:
        print(second)

-L = [0] * (N + 1) -R = [0] * (N + 2) -A.append(0) -for i in range(1, N + 1): -    if i == 1: -        L[1] = 0 -        R[N + 1] = 0 -    L[i] = max(L[i - 1], A[i - 2]) -    R[N - i + 1] = max(R[N - i + 2], A[N - i + 1]) -for i in range(1, N + 1): -    print((max(L[i], R[i]))) +B = A.copy() +B.sort(key=lambda x: -x) +last = B[0] +second = B[1] +for num in A: +    if num != last: +        print(last) +    else: +        print(second)