import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); TreeMap> positions = new TreeMap<>(); TreeSet idxes = new TreeSet<>(); for (int i = 0; i < n; i++) { int x = -sc.nextInt(); if (!positions.containsKey(x)) { positions.put(x, new ArrayList<>()); } positions.get(x).add(i); idxes.add(i); } int[] ans = new int[n]; for (int x : positions.keySet()) { if (positions.get(x).size() == 0) { int y = positions.get(x).get(0); if (idxes.contains(y)) { ans[y] = -x; idxes.remove(y); } } else { int left = positions.get(x).get(0); int right = positions.get(x).get(positions.get(x).size() - 1); Integer key = left - 1; while ((key = idxes.higher(key)) != null) { if (key > right) { break; } ans[key] = -x; idxes.remove(key); } } } StringBuilder sb = new StringBuilder(); for (int i = 0; i < n; i++) { if (i > 0) { sb.append(" "); } sb.append(ans[i]); } System.out.println(sb); } }