import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); TreeMap> pattern = new TreeMap<>(); int[] values = new int[n]; TreeSet remain = new TreeSet<>(); for (int i = 0; i < n; i++) { values[i] = sc.nextInt(); if (!pattern.containsKey(-values[i])) { pattern.put(-values[i], new ArrayList<>()); } pattern.get(-values[i]).add(i); remain.add(i); } for (int x : pattern.keySet()) { ArrayList list = pattern.get(x); Integer key = list.get(0) - 1; while ((key = remain.higher(key)) != null) { if (key > list.get(list.size() - 1)) { break; } values[key] = -x; remain.remove(key); } } StringBuilder sb = new StringBuilder(); for (int i = 0; i < n; i++) { if (i > 0) { sb.append(" "); } sb.append(values[i]); } System.out.println(sb); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public String nextLine() throws Exception { return br.readLine(); } public String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }