# 最大値と二番目に大きいやつをとっておく。最大値のときだけ二番目に大きいやつ採用

n = int(eval(input()))

arr = []

for i in range(n):

  t = int(eval(input())) 

  arr.append([i, t])



sorted_arr = list(sorted(arr, key = lambda x : x[1]))

biggest = sorted_arr[-1]

second_biggest = sorted_arr[-2]



for i in range(n):

  if i != biggest[0]:

    print((biggest[1]))

  else:

    print((second_biggest[1]))

n = int(eval(input()))

max_n = -1

semi_max_n = -1

max_idx = -1

for i in range(n):

    x = int(eval(input()))

    if x > max_n:

        max_n = x

        max_idx = i

    elif x >= semi_max_n:

        semi_max_n = x

for i in range(n):

    if i == max_idx:

        print(semi_max_n)

    else:

        print(max_n)
# 最大値と二番目に大きいやつをとっておく。最大値のときだけ二番目に大きいやつ採用
n = int(eval(input()))
arr = []
for i in range(n):
    t = int(eval(input()))
    arr.append([i, t])
sorted_arr = list(sorted(arr, key=lambda x: x[1]))
biggest = sorted_arr[-1]
second_biggest = sorted_arr[-2]
for i in range(n):
    if i != biggest[0]:
        print((biggest[1]))
    else:
        print((second_biggest[1]))

n = int(eval(input()))
max_n = -1
semi_max_n = -1
max_idx = -1
for i in range(n):
    x = int(eval(input()))
    if x > max_n:
        max_n = x
        max_idx = i
    elif x >= semi_max_n:
        semi_max_n = x
for i in range(n):
    if i == max_idx:
        print(semi_max_n)
    else:
        print(max_n)

-# 最大値と二番目に大きいやつをとっておく。最大値のときだけ二番目に大きいやつ採用 -arr = [] +max_n = -1 +semi_max_n = -1 +max_idx = -1 -    t = int(eval(input())) -    arr.append([i, t]) -sorted_arr = list(sorted(arr, key=lambda x: x[1])) -biggest = sorted_arr[-1] -second_biggest = sorted_arr[-2] +    x = int(eval(input())) +    if x > max_n: +        max_n = x +        max_idx = i +    elif x >= semi_max_n: +        semi_max_n = x -    if i != biggest[0]: -        print((biggest[1])) +    if i == max_idx: +        print(semi_max_n) -        print((second_biggest[1])) +        print(max_n)