N = int(input())
l = []
for i in range(N):
    A = int(input())
    l.append(A)
ans = [0]*N
m = max(l)
for i in range(N):
    n = l[i]
    if  n == m:
        l[i] = 0
        ans[i] = max(l)
        ans = ans[:i+1]
        ans.extend([n]*(N-i-1))
        break
    ans[i] = max(l)
[print(i) for i in ans]
