n = int(eval(input()))

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

a_m = max(a)

a_i = a.index(a_m)

a.sort()

for i in range(len(a)):

  if i == a_i:

    print((a[-2]))

  else:

    print(a_m)
from sys import stdin

n = int(stdin.readline().rstrip())

li = list(int(stdin.readline().rstrip()) for _ in range(n))

li_to = sorted(li)

one = li_to[-1]

two = li_to[-2]

for i in range(n):

    if one == li[i]:

        print(two)

    else:

        print(one)
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
a_m = max(a)
a_i = a.index(a_m)
a.sort()
for i in range(len(a)):
    if i == a_i:
        print((a[-2]))
    else:
        print(a_m)

from sys import stdin

n = int(stdin.readline().rstrip())
li = list(int(stdin.readline().rstrip()) for _ in range(n))
li_to = sorted(li)
one = li_to[-1]
two = li_to[-2]
for i in range(n):
    if one == li[i]:
        print(two)
    else:
        print(one)

-n = int(eval(input())) -a = [int(eval(input())) for _ in range(n)] -a_m = max(a) -a_i = a.index(a_m) -a.sort() -for i in range(len(a)): -    if i == a_i: -        print((a[-2])) +from sys import stdin + +n = int(stdin.readline().rstrip()) +li = list(int(stdin.readline().rstrip()) for _ in range(n)) +li_to = sorted(li) +one = li_to[-1] +two = li_to[-2] +for i in range(n): +    if one == li[i]: +        print(two) -        print(a_m) +        print(one)