import sys





def input():

    return sys.stdin.readline().strip()





N = int(input())

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

left = [0] * N

right = [0] * N

for i in range(1, N):

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

    right[N - i - 1] = max(A[N - i], right[N - i])

[print(max(left[i], right[i])) for i in range(N)]

N, *A = list(map(int, open(0).read().split()))

sorted_A = sorted(A)

for a in A:

    if a == sorted_A[-1]:

        print((sorted_A[-2]))

    else:

        print((sorted_A[-1]))

import sys


def input():
    return sys.stdin.readline().strip()


N = int(input())
A = [int(input()) for _ in range(N)]
left = [0] * N
right = [0] * N
for i in range(1, N):
    left[i] = max(A[i - 1], left[i - 1])
    right[N - i - 1] = max(A[N - i], right[N - i])
[print(max(left[i], right[i])) for i in range(N)]

N, *A = list(map(int, open(0).read().split()))
sorted_A = sorted(A)
for a in A:
    if a == sorted_A[-1]:
        print((sorted_A[-2]))
    else:
        print((sorted_A[-1]))

-import sys - - -def input(): -    return sys.stdin.readline().strip() - - -N = int(input()) -A = [int(input()) for _ in range(N)] -left = [0] * N -right = [0] * N -for i in range(1, N): -    left[i] = max(A[i - 1], left[i - 1]) -    right[N - i - 1] = max(A[N - i], right[N - i]) -[print(max(left[i], right[i])) for i in range(N)] +N, *A = list(map(int, open(0).read().split())) +sorted_A = sorted(A) +for a in A: +    if a == sorted_A[-1]: +        print((sorted_A[-2])) +    else: +        print((sorted_A[-1]))