n = int(eval(input()))

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

Sort_num = sorted(num)

for i in range(n):

  if num[i] == Sort_num[n-1]:

    print((Sort_num[n-2]))

  else:

    print((Sort_num[n-1]))

from copy import deepcopy

n=int(eval(input()))

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

b = deepcopy(a)

b.sort()



for i in range(n):

    if a[i] == b[-1]:

        print((b[-2]))

    else:

        print((b[-1]))

n = int(eval(input()))
num = [int(eval(input())) for _ in range(n)]
Sort_num = sorted(num)
for i in range(n):
    if num[i] == Sort_num[n - 1]:
        print((Sort_num[n - 2]))
    else:
        print((Sort_num[n - 1]))

from copy import deepcopy

n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
b = deepcopy(a)
b.sort()
for i in range(n):
    if a[i] == b[-1]:
        print((b[-2]))
    else:
        print((b[-1]))

+from copy import deepcopy + -num = [int(eval(input())) for _ in range(n)] -Sort_num = sorted(num) +a = [int(eval(input())) for _ in range(n)] +b = deepcopy(a) +b.sort() -    if num[i] == Sort_num[n - 1]: -        print((Sort_num[n - 2])) +    if a[i] == b[-1]: +        print((b[-2])) -        print((Sort_num[n - 1])) +        print((b[-1]))