n=int(eval(input()))

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

left=[0]

for i in a:

  left.append(max(left[-1],i))

right=[0]

for i in reversed(a):

  right.append(max(right[-1],i))

right.reverse()

for i in range(n):

  print((max(left[i],right[i+1])))

n = int(eval(input()))

a = [int(eval(input())) for i in range(n)]

b = sorted(a)

max1, max2 = b[-1], b[-2]

for i in a:

    if i == max1:

        print(max2)

    else:

        print(max1)
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
left = [0]
for i in a:
    left.append(max(left[-1], i))
right = [0]
for i in reversed(a):
    right.append(max(right[-1], i))
right.reverse()
for i in range(n):
    print((max(left[i], right[i + 1])))

n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
b = sorted(a)
max1, max2 = b[-1], b[-2]
for i in a:
    if i == max1:
        print(max2)
    else:
        print(max1)

-a = [int(eval(input())) for _ in range(n)] -left = [0] +a = [int(eval(input())) for i in range(n)] +b = sorted(a) +max1, max2 = b[-1], b[-2] -    left.append(max(left[-1], i)) -right = [0] -for i in reversed(a): -    right.append(max(right[-1], i)) -right.reverse() -for i in range(n): -    print((max(left[i], right[i + 1]))) +    if i == max1: +        print(max2) +    else: +        print(max1)