import sys
input = sys.stdin.readline
 
n = int(input()) 
num = [input() for _ in range(n)] 
#ma=max(num)
#ind=num.index(ma)
sorted_num=sorted(num)
ma=sorted_num[-1]
ma2=sorted_num[-2]
for i in range(n):
    if ma==num[i]:
        print(str(ma2).strip())
    else:
        print(str(ma).strip())