N = int(input())
s = [input() for i in range(N)]
if N>=2:
    x=sorted(s)[-1]
    y=sorted(s)[-2]
    for i in range(N):
        if s[i]==x:
            print(y)
        else:
            print(x)
else:
    print(s[0])
