

n = int(input())
a = []
for i in range(n):
  a.append(input())

dup = [x for x in set(a) if a.count(x) > 1]

tmp_a = sorted(list(set(a)), reverse=True)
no1 = tmp_a[0]
no2 = tmp_a[1] if len(tmp_a)>1 else tmp_a[0]

for each in a:
  if each == no1 and each not in dup:
    print(no2)
  else:
    print(no1)
