N = int(input())
arg = [input() for i in range(N)]

arg_sorted = list(set(arg))
arg_sorted.sort(reverse=True)

for val in arg:
  if val == arg_sorted[0] and len(arg_sorted) != 1:
    print(arg_sorted[1])
  else:
    print(arg_sorted[0])