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