#134

N = int(input())
A_max = 0
A_max_s = 0
flag = 0
A = []

for i in range(N):
    a = int(input())
    A.append(a)
    if a > A_max:
        A_max_s = A_max
        A_max = a
        ind_max = i
    elif A_max_s < a < A_max:
        A_max_s = a
    elif a == A_max:
        flag += 1
        
if flag >= 1:
    for i in range(N):
        print(A_max)
elif flag == 0:
    for i in range(N):
        if i != ind_max:
            print(A_max)
        else:
            print(A_max_s)

    
    