n = int(input())
nums = [input() for i in range(n)]
m = sorted(nums)[-1]
m2 = sorted(nums)[-2]
if m == m2:
  [print(m) for i in range(n)]
else:
  [print(m) if nums[i] != m else print(m2) for i in range(n)]