N = int(input())
li = []
for _ in range(N):
    li.append(int(input()))

max_indexs =  [i for i, x in enumerate(li) if x == max(li)]
li.sort()
max_val = li[-1]

if len(max_indexs) == 1:
    for i in range(N):
        if i == max_indexs[0]:
            print(li[-2])
        else:
            print(max_val)
else:
    for i in range(N):
        print(max_val)