n = int(input())
list = []
max = 0

for i in range(n):
    num = int(input())
    if num > max:
        max = num
    list.append(num)

max_index = [i for i,x in enumerate(list) if x == max]
#print(max_index)

list2 = [i for i in list if i != max]
#print(list2)
if list2 != []:
    second = sorted(list2)[-1]
else:
    second = 0
#print(second)

for i in range(n):
    if (i in max_index) & (len(max_index) == 1):
        print(second)
    else:
        print(max)
