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


for i in range(N):
    li.append(input())

new_li = sorted(li, reverse=True)

M = new_li[0]
m = new_li[1]

for i in range(N):
    if li[i] != M:
        print(M)
    else:
        print(m)