N = int(input())
li = []
for _ in range(N):
    r = int(input())
    li.append(r)
li_uniq = list(set(li))
li_uniq.sort(reverse = True)
Max1 = li_uniq[0]
Max2 = li_uniq[1]
for i in li:
    if i == Max1:
        print(Max2)
    else:
        print(Max1)