import sys

import heapq

import copy



n = int(eval(input()))

a = []



for _ in range(n):

	a.append(-1 * int(eval(input())))



b = copy.deepcopy(a)

heapq.heapify(b)



for i in range(n):

	maximum = heapq.heappop(b)

	if maximum == a[i]:

		tmp = maximum

		maximum = heapq.heappop(b)

		print((maximum * (-1)))

		heapq.heappush(b,tmp)

	else:

		print((maximum * (-1)))

	heapq.heappush(b,maximum)

import bisect



n = int(eval(input()))



a = []

for _ in range(n):

  a.append(int(eval(input())))



a2 = sorted(a)



max_a = a2[-1]

index = bisect.bisect_left(a2,max_a)

num = n-index



if num > 1:

  for _ in range(n):

    print((a2[-1]))

else:

  for i in range(n):

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

      print((a2[-2]))

    else:

      print((a2[-1]))

import sys
import heapq
import copy

n = int(eval(input()))
a = []
for _ in range(n):
    a.append(-1 * int(eval(input())))
b = copy.deepcopy(a)
heapq.heapify(b)
for i in range(n):
    maximum = heapq.heappop(b)
    if maximum == a[i]:
        tmp = maximum
        maximum = heapq.heappop(b)
        print((maximum * (-1)))
        heapq.heappush(b, tmp)
    else:
        print((maximum * (-1)))
    heapq.heappush(b, maximum)

import bisect

n = int(eval(input()))
a = []
for _ in range(n):
    a.append(int(eval(input())))
a2 = sorted(a)
max_a = a2[-1]
index = bisect.bisect_left(a2, max_a)
num = n - index
if num > 1:
    for _ in range(n):
        print((a2[-1]))
else:
    for i in range(n):
        if a[i] == a2[-1]:
            print((a2[-2]))
        else:
            print((a2[-1]))

-import sys -import heapq -import copy +import bisect -    a.append(-1 * int(eval(input()))) -b = copy.deepcopy(a) -heapq.heapify(b) -for i in range(n): -    maximum = heapq.heappop(b) -    if maximum == a[i]: -        tmp = maximum -        maximum = heapq.heappop(b) -        print((maximum * (-1))) -        heapq.heappush(b, tmp) -    else: -        print((maximum * (-1))) -    heapq.heappush(b, maximum) +    a.append(int(eval(input()))) +a2 = sorted(a) +max_a = a2[-1] +index = bisect.bisect_left(a2, max_a) +num = n - index +if num > 1: +    for _ in range(n): +        print((a2[-1])) +else: +    for i in range(n): +        if a[i] == a2[-1]: +            print((a2[-2])) +        else: +            print((a2[-1]))