n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
a_max = max(a)
ind_M = a.index(a_max)
oth = max(max(a[:ind_M]), max(a[ind_M+1:]))
for i in range(n):
    if i != ind_M:
        print(a_max)
    else:
        print(oth)