import sys
import copy
 
N = int(input())
 
A = []
for n in range(N):
    A.append(int(input()))
A_copy = copy.copy(A)
max_A = max(A)
max_c = A.count(max_A)

for i in range(n):
    if A[i] != max_A :
        print(max_A)
    else:
        if max_c == 1:
            A[i] = 0
            print(max(A))
        else:
            print(max_A)
            
