N = int(eval(input()))

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

srt_A = sorted(lst_A, reverse=True)

m1 = srt_A[0]

m2 = srt_A[1]





for v in lst_A:

    print((m2 if v == m1 else m1))
import sys

input = sys.stdin.readline





N = int(eval(input()))

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

srt_A = sorted(lst_A, reverse=True)

m1 = srt_A[0]

m2 = srt_A[1]





for v in lst_A:

    print((m2 if v == m1 else m1))
N = int(eval(input()))
lst_A = [int(eval(input())) for _ in range(N)]
srt_A = sorted(lst_A, reverse=True)
m1 = srt_A[0]
m2 = srt_A[1]
for v in lst_A:
    print((m2 if v == m1 else m1))

import sys

input = sys.stdin.readline
N = int(eval(input()))
lst_A = [int(eval(input())) for _ in range(N)]
srt_A = sorted(lst_A, reverse=True)
m1 = srt_A[0]
m2 = srt_A[1]
for v in lst_A:
    print((m2 if v == m1 else m1))

+import sys + +input = sys.stdin.readline