# n = 3

n = int(eval(input()))



arr = [0]*n



for i in range(n):

	arr[i] = (int(eval(input())), i)



sorted_arr = sorted(arr, reverse=True)

lg, slg = sorted_arr[0][1], sorted_arr[1][1]

for i in range(n):

	if i==lg:

		print((arr[slg][0]))

	else:

		print((arr[lg][0]))
import heapq



n = int(eval(input()))

# n = 3



arr = [0]*n



pq = []

for i in range(n):

	arr[i] = int(eval(input()))

	heapq.heappush(pq, (-arr[i], i))

heapq.heapify(pq)

lg = heapq.heappop(pq)

slg = heapq.heappop(pq)

lg, slg = lg[1], slg[1]



for i in range(n):

	if i==lg:

		print((arr[slg]))

	else:

		print((arr[lg]))
# n = 3
n = int(eval(input()))
arr = [0] * n
for i in range(n):
    arr[i] = (int(eval(input())), i)
sorted_arr = sorted(arr, reverse=True)
lg, slg = sorted_arr[0][1], sorted_arr[1][1]
for i in range(n):
    if i == lg:
        print((arr[slg][0]))
    else:
        print((arr[lg][0]))

import heapq

n = int(eval(input()))
# n = 3
arr = [0] * n
pq = []
for i in range(n):
    arr[i] = int(eval(input()))
    heapq.heappush(pq, (-arr[i], i))
heapq.heapify(pq)
lg = heapq.heappop(pq)
slg = heapq.heappop(pq)
lg, slg = lg[1], slg[1]
for i in range(n):
    if i == lg:
        print((arr[slg]))
    else:
        print((arr[lg]))

+import heapq + +n = int(eval(input())) -n = int(eval(input())) +pq = [] -    arr[i] = (int(eval(input())), i) -sorted_arr = sorted(arr, reverse=True) -lg, slg = sorted_arr[0][1], sorted_arr[1][1] +    arr[i] = int(eval(input())) +    heapq.heappush(pq, (-arr[i], i)) +heapq.heapify(pq) +lg = heapq.heappop(pq) +slg = heapq.heappop(pq) +lg, slg = lg[1], slg[1] -        print((arr[slg][0])) +        print((arr[slg])) -        print((arr[lg][0])) +        print((arr[lg]))