N=input();b=[0]*N;n=range(1,N+1);d={} for i,v in enumerate(map(int,raw_input().split())): if v in d:d[v][1]=i else:d[v]=[i,i] for k,(l,r)in sorted(d.items())[::-1]: while l<=r: if b[l]==0:b[l]=k n[l],l=r,n[l] n[r]=l print " ".join(map(str,b))