N=input();a=map(int,raw_input().split()) b=[0]*(N+1);n=range(1,N+2);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.iteritems(),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[:N]))