def main():
    n = int(input())
    a_list = [int(input()) for _ in range(n)]
    a_sorted = sorted(a_list)
    a_first = a_sorted[-1]
    a_second = a_sorted[-2]
    a_count = a_list.count(a_first)

    if a_count >= 2:
        for a in a_list:
            print(a)
    else:
        for a in a_list:
            if a == a_first:
                print(a_second)
            else:
                print(a_first)


if __name__ == '__main__':
    main()
