n=int(input())
a= [input() for _ in range(n)]

la=sorted(a)
re=la[-2]
check=max(a)

x=a.count(check)

for i in range(n):
    if a[i]==check:
        if x>1:
            print(check)
        if x<=1:
            print(re)
    else:
        print(check)