n = int(input())

max_val = 0
sub_max_val = 0
max_indices = []
for i in range(n):
    ai = int(input())
    if ai > max_val:
        max_val = ai
        max_indices = [i]
    elif ai == max_val:
        max_indices.append(i)
    elif ai > sub_max_val:
        sub_max_val = ai

for i in range(n):
    if i in max_indices:
        print(sub_max_val)
    else:
        print(max_val)