n = int(input())
num = []
for i in range(n):
    num.append(int(input()))
#ここまで入力
num1 = num.copy()
num1.sort(reverse=True)
mx1 = num1[0]
mx2 = num1[1]
for i in num:
    if i==mx1:
        ans = mx2
        print(ans)
    else:
        ans = mx1
        print(ans)
