import copy
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
c = []
mL = 0
mR = 0
# m = 0
m = max(A)
S = copy.copy(A)
for s in S:
    if s == m:
        S.remove(s)
    # print(S[i])
s = max(S)    
# print(s)
for i, a in enumerate(A):
    # print(a)
    if a == m:
        print(s)
    else:
        print(m)
    # if i == 0:
    #     mR = max(A[i + 1 :])
    #     print(mR)
    # elif i == len(A) - 1:
    #     mL = max(A[0: i])
    #     print(mL)
    # else:
    #     mL = max(A[0: i])
    #     mR = max(A[i + 1 :])
    #     m = max(mL, mR)
    #     print(m)
    