n = int(input())
l = []
m = []

for i in range(n):
    l.append(int(input()))

x = 0
y = 0
count = 0

for i in l:
    for j in l:
        if i == j:
            count += 1

for i in l:
    if i > x:
        x = i
        
if count > 2:
    for i in range(n):
        print(x)

else:
    for i in l:
        if i != x:
            m.append(i)

    for i in m:
        if i > y:
            y = i
    
    for i in l:
        if i != x:
            print(x)
        else:
            print(y)