import math


def solve():
    n = int(input())
    al = [int(input()) for _ in range(n)]
    l = list(set(al))
    l.sort()
    if len(l) == 1:
        f, s = l[0], l[0]
    else:
        f, s = l[-1], l[-2]
    for a in al:
        if a == f:
            print(s)
        else:
            print(f)

if __name__ == "__main__":
    solve()