n = int(input())

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



first = 0

second = 1

if A[first] < A[second]:

    first, second = second, first

for i in range(2, n):

    if A[first] < A[i]:

        second = first

        first = i

    elif A[second] < A[i]:

        second = i



print(*[A[first] if i != first else A[second] for i in range(n)], sep='\n')

import heapq



n = int(input())

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

m1, m2 = heapq.nlargest(2, A)

print(*[m2 if a == m1 else m1 for a in A], sep='\n')

n = int(input())
A = [int(input()) for _ in range(n)]
first = 0
second = 1
if A[first] < A[second]:
    first, second = second, first
for i in range(2, n):
    if A[first] < A[i]:
        second = first
        first = i
    elif A[second] < A[i]:
        second = i
print(*[A[first] if i != first else A[second] for i in range(n)], sep="\n")

import heapq

n = int(input())
A = [int(input()) for _ in range(n)]
m1, m2 = heapq.nlargest(2, A)
print(*[m2 if a == m1 else m1 for a in A], sep="\n")

+import heapq + -first = 0 -second = 1 -if A[first] < A[second]: -    first, second = second, first -for i in range(2, n): -    if A[first] < A[i]: -        second = first -        first = i -    elif A[second] < A[i]: -        second = i -print(*[A[first] if i != first else A[second] for i in range(n)], sep="\n") +m1, m2 = heapq.nlargest(2, A) +print(*[m2 if a == m1 else m1 for a in A], sep="\n")