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