map = Struct.new(:min, :max) map2 = Struct.new(:num, :range) n = gets.to_i a = gets.split.map(&:to_i) b = Array.new(n).map{map2.new(0, map.new)} c = Hash.new d = Array.new find = false n.times do |i| if !c.has_key?(a[i]) c[a[i]] = map.new(i, i) else c[a[i]].max = i find = true end d.push(a[i]) end if !find puts a.join(" ") exit end d.uniq!.sort!{|a, b| b <=> a} d.each do |x| r = c[x] t = map.new(r.min, r.max) i = r.min while i <= r.max do if b[i].num == 0 b[i].num = x b[i].range = t i += 1 else if b[i].range.min > r.min b[i].range.min = r.min end si = b[i].range.max + 1 if b[i].range.max < r.max b[i].range.max = r.max end i = si end end end sp = false b.each do |x| if sp print " " end print x.num sp = true end puts