import numpy as np

N = int(input())
A = []


for _ in range(N):
    A.append(int(input()))
    
a = b = A[0]
    
for i in range(N):
    if A[i] > a:
        a = A[i]
    elif A[i] > b:
        b = A[i]

for i in range(N):
    if A[i] < a:
        print(a)
    else:
        print(b)