N = int(input())
A = []
for _ in range(N):
    A.append(int(input()))

import heapq

h = []
for a in A:
    if len(h) < 2:
        heapq.heappush(h, a)
    else:
        heapq.heappushpop(h, a)

print('h', h)

for a in A:
    if a == h[1]:  # 最も大きい数値
        print(h[0])
    else:
        print(h[1])