N = int(input().strip())
f = 0
s = 0
c = 0
A = []

for i in range(N):
    A.append(int(input().strip()))
    if f < A[i]:
        f = A[i]
    
    if s < A[i] and A[i] < f:
        s = A[i]
        c += 1
        if c >= 2:
            s = f

for i in range(N):
    if A[i] == f:
        print(f if s == 0 else s)
    else:
        print(f)