# 累積和(max)

N = int(eval(input()))

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

lcm = a[:]

rcm = a[:]

for i in range(1, N):

  lcm[i] = max(lcm[i], lcm[i - 1])

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

  rcm[i] = max(rcm[i], rcm[i + 1])

print((rcm[1]))

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

  print((max(lcm[i - 1], rcm[i + 1])))

print((lcm[N - 2]))

N = int(eval(input()))

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



b = A[:]

b.sort(reverse=True)

for i in range(N):

    if A[i] != b[0]:

        print((b[0]))

    else:

        print((b[1]))

# 累積和(max)
N = int(eval(input()))
a = [int(eval(input())) for _ in range(N)]
lcm = a[:]
rcm = a[:]
for i in range(1, N):
    lcm[i] = max(lcm[i], lcm[i - 1])
for i in range(N - 2, -1, -1):
    rcm[i] = max(rcm[i], rcm[i + 1])
print((rcm[1]))
for i in range(1, N - 1):
    print((max(lcm[i - 1], rcm[i + 1])))
print((lcm[N - 2]))

N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
b = A[:]
b.sort(reverse=True)
for i in range(N):
    if A[i] != b[0]:
        print((b[0]))
    else:
        print((b[1]))

-# 累積和(max) -a = [int(eval(input())) for _ in range(N)] -lcm = a[:] -rcm = a[:] -for i in range(1, N): -    lcm[i] = max(lcm[i], lcm[i - 1]) -for i in range(N - 2, -1, -1): -    rcm[i] = max(rcm[i], rcm[i + 1]) -print((rcm[1])) -for i in range(1, N - 1): -    print((max(lcm[i - 1], rcm[i + 1]))) -print((lcm[N - 2])) +A = [int(eval(input())) for _ in range(N)] +b = A[:] +b.sort(reverse=True) +for i in range(N): +    if A[i] != b[0]: +        print((b[0])) +    else: +        print((b[1]))