from sys import stdin
N = int(stdin.readline().rstrip())
num_line = [stdin.readline().rstrip() for _ in range(N)]
sort_line = sorted(num_line)
for i in num_line:
    if i == sort_line[-1]:
        print(sort_line[-2])
    else:
        print(sort_line[-1])