# For taking integer inputs.
def inp():
    return(int(input()))


N = inp()
A = []
m1, m2 = 0, 0
for i in range(N):
    A.append(inp())
    if A[i] > m1:
        m1 = A[i]
    if A[i] > m2 and A[i] < m1:
        m2 = A[i]
if m2 == 0:
    m2 = m1
for i in range(N):
    if A[i] != m1:
        print(m1)
    else:
        print(m2)
