n=int(eval(input()))



import heapq

a=[]

a_heap=[]

for i in range(n):

    tmp=int(eval(input()))

    a.append(tmp)

    heapq.heappush(a_heap,(-1)*tmp)



for i in range(n):

    max_1=heapq.heappop(a_heap)

    if max_1==(-1)*a[i]:

        max_2=heapq.heappop(a_heap)

        print(((-1)*max_2))

        heapq.heappush(a_heap,max_2)

    else:print(((-1)*max_1))

    heapq.heappush(a_heap,max_1)
n=int(eval(input()))



a=[]

a_sort=[]

for i in range(n):

    tmp=int(eval(input()))

    a.append(tmp)

    a_sort.append(tmp)

a_sort.sort(reverse=True)



for i in range(n):

    if a_sort[0]==a[i]:print((a_sort[1]))

    else:print((a_sort[0]))
n = int(eval(input()))
import heapq

a = []
a_heap = []
for i in range(n):
    tmp = int(eval(input()))
    a.append(tmp)
    heapq.heappush(a_heap, (-1) * tmp)
for i in range(n):
    max_1 = heapq.heappop(a_heap)
    if max_1 == (-1) * a[i]:
        max_2 = heapq.heappop(a_heap)
        print(((-1) * max_2))
        heapq.heappush(a_heap, max_2)
    else:
        print(((-1) * max_1))
    heapq.heappush(a_heap, max_1)

n = int(eval(input()))
a = []
a_sort = []
for i in range(n):
    tmp = int(eval(input()))
    a.append(tmp)
    a_sort.append(tmp)
a_sort.sort(reverse=True)
for i in range(n):
    if a_sort[0] == a[i]:
        print((a_sort[1]))
    else:
        print((a_sort[0]))

-import heapq - -a_heap = [] +a_sort = [] -    heapq.heappush(a_heap, (-1) * tmp) +    a_sort.append(tmp) +a_sort.sort(reverse=True) -    max_1 = heapq.heappop(a_heap) -    if max_1 == (-1) * a[i]: -        max_2 = heapq.heappop(a_heap) -        print(((-1) * max_2)) -        heapq.heappush(a_heap, max_2) +    if a_sort[0] == a[i]: +        print((a_sort[1])) -        print(((-1) * max_1)) -    heapq.heappush(a_heap, max_1) +        print((a_sort[0]))