import sys
import bisect
input = sys.stdin.readline
 
def main():
    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
                if(a[j]>ans):
                    ans=a[j]
            
        print(ans)        
main()


