# ABC 134, C -
from operator import itemgetter

n = int(input())

A = []
for i in range(n):
    A.append(int(input()))

B = sorted(A)
maxima, maxima_ind = B[len(B)-1], len(B)-1
sec_maxima, sec_maxima_ind = B[len(B)-2], len(B)-2




for i in range(n):
    if i == maxima_ind:
        print(sec_maxima)
    else:
        print(maxima)


