n = int(input())

a = []
b = set()
for _ in range(n):
    tmp = int(input())
    a.append(tmp)
    b.add(tmp)

max_num = max(b)
max_num_set = set()
max_num_set.add(max_num)
c = b - max_num_set
if len(c) == 0:
    second_max_num = max_num
else:
    second_max_num = max(c)

for elem in a:
    if elem == max_num:
        print(second_max_num)
    else:
        print(max_num)
