import sys

input = sys.stdin.readline

import numpy as np

n = int(eval(input())) 

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

num = np.array(num).astype("int64")

#ma=max(num)

#ind=num.index(ma)

sorted_num=sorted(num)

ma=sorted_num[-1]

ma2=sorted_num[-2]

for i in range(n):

    if ma != num[i]:

        print((str(ma).strip()))

    else:

        print((str(ma2).strip()))
import sys

input = sys.stdin.readline



n = int(eval(input())) 

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

ma=max(num)

ind=num.index(ma)

ma2=sorted(num)[-2]

for i in range(n):

    if ind==i:

        print(ma2)

    else:

        print(ma)
import sys

input = sys.stdin.readline
import numpy as np

n = int(eval(input()))
num = [eval(input()) for _ in range(n)]
num = np.array(num).astype("int64")
# ma=max(num)
# ind=num.index(ma)
sorted_num = sorted(num)
ma = sorted_num[-1]
ma2 = sorted_num[-2]
for i in range(n):
    if ma != num[i]:
        print((str(ma).strip()))
    else:
        print((str(ma2).strip()))

import sys

input = sys.stdin.readline
n = int(eval(input()))
num = [int(eval(input())) for _ in range(n)]
ma = max(num)
ind = num.index(ma)
ma2 = sorted(num)[-2]
for i in range(n):
    if ind == i:
        print(ma2)
    else:
        print(ma)

-import numpy as np - -num = [eval(input()) for _ in range(n)] -num = np.array(num).astype("int64") -# ma=max(num) -# ind=num.index(ma) -sorted_num = sorted(num) -ma = sorted_num[-1] -ma2 = sorted_num[-2] +num = [int(eval(input())) for _ in range(n)] +ma = max(num) +ind = num.index(ma) +ma2 = sorted(num)[-2] -    if ma != num[i]: -        print((str(ma).strip())) +    if ind == i: +        print(ma2) -        print((str(ma2).strip())) +        print(ma)