N = int(input())
list = [int(input()) for i in range(N)]
if sorted(list)[-1] == sorted(list)[-2]:
    list2 = [max(list) for i in range(N)]
    print("\n".join(map(str,list2)))
else:
    list2 = [max(list) for i in range(list.index(max(list)))]
    list2.append(sorted(list)[-2])
    list3 = [max(list) for j in range(list.index(max(list))+1,N)]
    list2.extend(list3)
    print("\n".join(map(str,list2)))