N = int(eval(input()))

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

left_max = [0] * (N + 1)

right_max = [0] * (N + 1)



for index, a in enumerate(A, start=1):

    left_max[index] = max(left_max[index - 1], a)



for index, a in enumerate(reversed(A), start=1):

    right_max[index] = max(right_max[index - 1], a)



for i in range(N):

    print((max(left_max[i], right_max[N - i - 1])))

N = int(eval(input()))

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



max1 = 0

max2 = 0



for a in A:

    if a > max1:

        max2 = max1

        max1 = a

    elif a > max2:

        max2 = a



for a in A:

    if a == max1:

        print(max2)

    else:

        print(max1)

N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
left_max = [0] * (N + 1)
right_max = [0] * (N + 1)
for index, a in enumerate(A, start=1):
    left_max[index] = max(left_max[index - 1], a)
for index, a in enumerate(reversed(A), start=1):
    right_max[index] = max(right_max[index - 1], a)
for i in range(N):
    print((max(left_max[i], right_max[N - i - 1])))

N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
max1 = 0
max2 = 0
for a in A:
    if a > max1:
        max2 = max1
        max1 = a
    elif a > max2:
        max2 = a
for a in A:
    if a == max1:
        print(max2)
    else:
        print(max1)

-left_max = [0] * (N + 1) -right_max = [0] * (N + 1) -for index, a in enumerate(A, start=1): -    left_max[index] = max(left_max[index - 1], a) -for index, a in enumerate(reversed(A), start=1): -    right_max[index] = max(right_max[index - 1], a) -for i in range(N): -    print((max(left_max[i], right_max[N - i - 1]))) +max1 = 0 +max2 = 0 +for a in A: +    if a > max1: +        max2 = max1 +        max1 = a +    elif a > max2: +        max2 = a +for a in A: +    if a == max1: +        print(max2) +    else: +        print(max1)