n = int(input())
a = []
for _ in range(n):
    a.append(int(input()))
firstMax = max(a)
minVal = min(a)
secondMax = max(map(lambda x:x if x != firstMax else minVal, a))
for i in range(len(a)):
    if a[i] < firstMax:
        print(firstMax)
    else:
        print(secondMax)