n = int(eval(input()))

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



b = sorted(a)



for i in range(n):

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

    print((b[-2]))

  else:

    print((b[-1]))

import sys

input = sys.stdin.buffer.readline

N = int(eval(input()))

A = [int(eval(input())) for _ in range(N)]

max_A = max(A)

sorted_A = sorted(A, reverse=True)

if sorted_A[1] == max_A:

    for _ in range(N):

        print(max_A)

    exit()



for a in A:

    if a == max_A:

        print((sorted_A[1]))

    else:

        print(max_A)

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

import sys

input = sys.stdin.buffer.readline
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
max_A = max(A)
sorted_A = sorted(A, reverse=True)
if sorted_A[1] == max_A:
    for _ in range(N):
        print(max_A)
    exit()
for a in A:
    if a == max_A:
        print((sorted_A[1]))
    else:
        print(max_A)

-n = int(eval(input())) -a = [int(eval(input())) for _ in range(n)] -b = sorted(a) -for i in range(n): -    if a[i] == b[-1]: -        print((b[-2])) +import sys + +input = sys.stdin.buffer.readline +N = int(eval(input())) +A = [int(eval(input())) for _ in range(N)] +max_A = max(A) +sorted_A = sorted(A, reverse=True) +if sorted_A[1] == max_A: +    for _ in range(N): +        print(max_A) +    exit() +for a in A: +    if a == max_A: +        print((sorted_A[1])) -        print((b[-1])) +        print(max_A)