N = int(input())

nums = [int(input()) for x in range(N)]

a = sorted(nums)[-1]#max(nums)
b = sorted(nums)[-2]#max(nums.remove(max_num))



if a == b:
    for _ in range(nums):
        print(a)
else:
    for x in [b if x == a else a for x in nums]:
        print(x)