from collections import defaultdict import sys readline=sys.stdin.readline class Dual_Segment_Tree: def __init__(self,N,f_act,e_act,operate,lst): self.N=N self.f_act=f_act self.e_act=e_act self.operate=operate self.lst=[None]*self.N for i,x in enumerate(lst): self.lst[i]=x self.segment_tree_act=[self.e_act]*(self.N+self.N) def __getitem__(self,i): if type(i) is int: if -self.N<=i<0: i+=self.N*2 elif 0<=i>h) def Operate_Range(self,a,L=None,R=None): if L==None: L=self.N else: L+=self.N if R==None: R=self.N*2 else: R+=self.N L0=L//(L&-L) R0=R//(R&-R)-1 self.Propagate_Above(L0) self.Propagate_Above(R0) while L>=1 R>>=1 def Update(self): for i in range(1,self.N): self.Propagate_At(i) self.segment_tree_act[i]=self.e_act def __str__(self): import copy segment_tree_act=copy.deepcopy(self.segment_tree_act) for i in range(1,self.N): segment_tree_act[i<<1]=self.f_act(segment_tree_act[i<<1],segment_tree_act[i]) segment_tree_act[i<<1|1]=self.f_act(segment_tree_act[i<<1|1],segment_tree_act[i]) segment_tree_act[i]=self.e_act segment_tree_act[i]=self.e_act return '['+', '.join(map(str,[self.operate(x,a) for x,a in zip(self.lst,segment_tree_act[self.N:])]))+']' N=int(readline()) A=list(map(int,readline().split())) idx=defaultdict(list) for i in range(N): idx[A[i]].append(i) def f_act(a,b): if b==None: return a return b e_act=None def operate(x,a): if a==None: return x return a DST=Dual_Segment_Tree(N,f_act,e_act,operate,A) for a in sorted(list(idx.keys())): DST.Operate_Range(a,idx[a][0],idx[a][-1]+1) print(*DST)