import heapq
N = int(input())
A = []

for _ in range(N):
    A.append((-1)*(int(input())))

B = A.copy()

heapq.heapify(B)
max_1 = 0 - heapq.heappop(B)
max_2 = 0 - heapq.heappop(B)

if max_1 == max_2:
    for _ in range(N):
        print(max_1)
        
else:
    for i in range(N):
        if i == A.index(-max_1):
            print(max_2)
        else:
            print(max_1)

    
