n=int(input())
a=[0 for _ in range(n)]
for i in range(n):
    a[i]=int(input())
M=max(a)
ans=0
for i in range(n):
    if(a[i]!=M):
        ans=M
    else:
        ans=0
        for j in range(n-1):
            if(j>=i):
                j+=1
            ans=max(ans,a[j])
        
    print(ans)        

