N = int(eval(input()))

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

sortedA = sorted(A, reverse=True)



for a in A:

    if sortedA[0] != a:

        print((sortedA[0]))

    else:

        print((sortedA[1]))
import sys

N = int(eval(input()))

A = [int(sys.stdin.readline()) for _ in range(N)]

sortedA = sorted(A, reverse=True)

for a in A:

    if a == sortedA[0]:

        print((sortedA[1]))

    else:

        print((sortedA[0]))
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
sortedA = sorted(A, reverse=True)
for a in A:
    if sortedA[0] != a:
        print((sortedA[0]))
    else:
        print((sortedA[1]))

import sys

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

+import sys + -A = [int(eval(input())) for _ in range(N)] +A = [int(sys.stdin.readline()) for _ in range(N)] -    if sortedA[0] != a: +    if a == sortedA[0]: +        print((sortedA[1])) +    else: -    else: -        print((sortedA[1]))