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

#a_sort = sorted(set(a))
max_1 = max(a)
for i in range(n):
    if max_1 == a[i]:
        a[i] = int(-1)
        #print("change")

max_2 = max(a)

for i in range(n):
    if a[i] == -1:
        a[i] = max_1
      

print ("max: " + str(max_1), "max2: " + str(max_2))

for i in range(n):
    if max_1 >= a[i]:
        print(max_1)
    
    elif a[i] < max:
        print(max_2)

    elif a[i] == max_val_1 and max_total_1 == 1:
        print(max_2)
    else:
        print("err")