n = int(input())
ls = []
for i in range(n):
    ls.append(int(input()))
maxnum = max(ls)
ind = ls.index(maxnum)
ls.remove(maxnum)
secondnum = max(ls)
ls = ls[0:i] + [maxnum] + ls[i+1:]
if maxnum == secondnum:
    for i in range(n):
        print(maxnum)
    quit()
for i in range(n):
    if ls[i] == maxnum:
        print(secondnum)
    else:
        print(maxnum)
