n = int(input())
_list = []

for _ in range(n):
    _list.append(int(input()))

_set = set(_list)
sort_list = sorted(list(_set))

if len(sort_list) != 1:
    first = sort_list[-1]
    second = sort_list[-2]

    for i in range(n):
        if _list[i] != first:
            print(first)
        else:
            print(second)

else:
    first = sort_list[0]

    for _ in range(n):
        print(first)