Mike is the president of country What-The-Fatherland. There are n bears living in this country besides Mike. All of them are standing in a line and they are numbered from 1 to n from left to right. i-th bear is exactly ai feet high. 

<image>

A group of bears is a non-empty contiguous segment of the line. The size of a group is the number of bears in that group. The strength of a group is the minimum height of the bear in that group.

Mike is a curious to know for each x such that 1 ≤ x ≤ n the maximum strength among all groups of size x.

Input

The first line of input contains integer n (1 ≤ n ≤ 2 × 105), the number of bears.

The second line contains n integers separated by space, a1, a2, ..., an (1 ≤ ai ≤ 109), heights of bears.

Output

Print n integers in one line. For each x from 1 to n, print the maximum strength among all groups of size x.

Examples

Input

10
1 2 3 4 5 4 3 2 1 6


Output

6 4 4 3 3 2 2 1 1 1 
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class CFProblemD {

	public static void main(String[] args) {
		FastScanner input = new FastScanner();
		int n = input.nextInt();
		int[] arr = new int[n];
		PriorityQueue<Point> points = new PriorityQueue<Point>();
		for (int a = 0; a < n; a++) {
			arr[a] = input.nextInt();
			points.add(new Point(arr[a], a));
		}

		ArrayList<Integer>[] sets = new ArrayList[n+1];
		int maxSetSize = 0;
		int[] mapToSet = new int[n+1];
		Arrays.fill(mapToSet, -1);
		int setID = 0;
		int[] output = new int[n + 1];
		int currentMin = -1;
		while (maxSetSize != n) {
			Point tmp = points.poll();
			int id = tmp.startIndex;
			int id1 = id + 1;
			int idm1 = id - 1;
			currentMin = tmp.value;

			ArrayList<Integer> neighbors = new ArrayList<Integer>();
			if (idm1 >= 0  && mapToSet[idm1] != -1) {
				neighbors.add(idm1);
			}
			if (id1 < mapToSet.length && mapToSet[id1] != -1) {
				neighbors.add(id1);
			}
			if (neighbors.size() == 0) {
				// create new
				sets[setID] = new ArrayList<Integer>();
				sets[setID].add(id);
				mapToSet[tmp.startIndex] = setID;
				setID++;
				if (maxSetSize < 1) {
					maxSetSize = 1;
				}
			} else {
				if (neighbors.size() == 1) {
					sets[mapToSet[neighbors.get(0)]].add(tmp.startIndex);
					mapToSet[tmp.startIndex] = mapToSet[neighbors.get(0)];
					if (maxSetSize < sets[mapToSet[neighbors.get(0)]].size()) {
						maxSetSize = sets[mapToSet[neighbors.get(0)]].size();
					}
				} else {
					int largerSetIndex = -1;
					int merge = -1;
					if (sets[mapToSet[neighbors.get(0)]].size() > sets[mapToSet[neighbors
							.get(1)]].size()) {
						// merge into 0
						largerSetIndex = 0;
						merge = 1;
					} else {
						largerSetIndex = 1;
						merge = 0;
						// merge into 1
					}
					ArrayList<Integer> destinationSet = sets[mapToSet[neighbors
							.get(largerSetIndex)]];
					int destinationSetID = mapToSet[neighbors
							.get(largerSetIndex)];
					int temp123 = mapToSet[neighbors.get(merge)];
					for (Integer mergeIt : sets[mapToSet[neighbors.get(merge)]]) {
						destinationSet.add(mergeIt);
						mapToSet[mergeIt] = destinationSetID;
					}
					sets[temp123] = null;
					sets[mapToSet[neighbors.get(largerSetIndex)]]
							.add(tmp.startIndex);
					mapToSet[tmp.startIndex] = mapToSet[neighbors
							.get(largerSetIndex)];
					if (maxSetSize < sets[mapToSet[neighbors
							.get(largerSetIndex)]].size()) {
						maxSetSize = sets[mapToSet[neighbors
								.get(largerSetIndex)]].size();
					}
				}
			}
			if (output[maxSetSize] == 0) {
				output[maxSetSize] = currentMin;
			}
		}
		int prev = -1;
		for (int a = n; a > 0; a--) {
			if (output[a] == 0) {
				output[a] = prev;
			}
			prev = output[a];
		}
		StringBuilder output2 = new StringBuilder();
		for (int a = 1; a <= n; a++) {
			output2.append(output[a] + " ");
		}

		System.out.println(output2);
	}

	public static class Point implements Comparable<Point> {
		int value;
		int startIndex;

		public Point(int _value, int _startIndex) {
			value = _value;
			startIndex = _startIndex;
		}

		@Override
		public int compareTo(Point arg0) {
			if (value == arg0.value) {
				return startIndex - arg0.startIndex;
			}
			return -1 * (value - arg0.value);
		}

	}

	public static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(Reader in) {
			br = new BufferedReader(in);
		}

		public FastScanner() {
			this(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		// Slightly different from java.util.Scanner.nextLine(),
		// which returns any remaining characters in current line,
		// if any.
		String readNextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
}
