import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; import java.util.Map; public class Main_yukicoder318 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Printer pr = new Printer(System.out); int n = sc.nextInt(); int[] a = new int[n]; Map hm = new HashMap(); for (int i = 0; i < n; i++) { a[i] = sc.nextInt(); if (hm.containsKey(a[i])) { Range r = hm.get(a[i]); if (r.e < i) { r.e = i; } } else { hm.put(a[i], new Range(a[i], i, i)); } } LinkedList list = new LinkedList(hm.values()); Collections.sort(list, Collections.reverseOrder()); // Deque st = new ArrayDeque(); int[] b = new int[n]; // for (int i = 0; i < n; i++) { // while (list.peekFirst().s == i) { // if (!st.isEmpty() && st.peek().t > list.peekFirst().t) { // list.removeFirst(); // continue; // } // st.push(list.removeFirst()); // } // // while (!st.isEmpty() && st.peek().e < i) { // st.pop(); // } for (Range e : list) { Arrays.fill(b, e.s, e.e + 1, e.t); } for (int i = 0; i < n; i++) { if (i != 0) { pr.print(" "); } pr.print(b[i]); } pr.println(); pr.close(); sc.close(); } private static class Range implements Comparable { int t; int s; int e; Range(int t, int s, int e) { this.t = t; this.s = s; this.e = e; } @Override public int compareTo(Range o) { // if (this.s != o.s) { // return Integer.compare(this.s, o.s); // } // if (this.e != o.e) { // return Integer.compare(o.e, this.e); // } if (this.t != o.t) { return Integer.compare(o.t, this.t); } return 0; } } @SuppressWarnings("unused") private static class Scanner { BufferedReader br; Iterator it; Scanner (InputStream in) { br = new BufferedReader(new InputStreamReader(in)); } String next() throws RuntimeException { try { if (it == null || !it.hasNext()) { it = Arrays.asList(br.readLine().split(" ")).iterator(); } return it.next(); } catch (IOException e) { throw new IllegalStateException(); } } int nextInt() throws RuntimeException { return Integer.parseInt(next()); } long nextLong() throws RuntimeException { return Long.parseLong(next()); } float nextFloat() throws RuntimeException { return Float.parseFloat(next()); } double nextDouble() throws RuntimeException { return Double.parseDouble(next()); } void close() { try { br.close(); } catch (IOException e) { // throw new IllegalStateException(); } } } private static class Printer extends PrintWriter { Printer(PrintStream out) { super(out); } } }