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.FileInputStream;
import java.io.*;
import java.util.Locale;
import java.util.StringTokenizer;


public class Task_Rnd305_D {

	public static void main(String[] args)
	{
		reader.init(true);	///!!!
		run();
		wr.flush();
	}

    public static void run()
    {
		int n = reader.nextInt();
		int aa[] = new int[n];
		for (int i = 0; i < n; i++)
			aa[i] = reader.nextInt();
		
		int LL[] = new int[n];
		int RR[] = new int[n];
		int ss[] = new int[n];
		int st = 0;
		
		for (int ii = 0; ii < n; ii++) {
			while (st > 0 && aa[ss[st-1]] >= aa[ii])
				st--;
			if (st == 0)
				LL[ii] = -1;
			else
				LL[ii] = ss[st-1];
			
			ss[st++] = ii;
		}

		st = 0;
		for (int ii = n-1; ii >= 0; ii--) {
			while (st > 0 && aa[ss[st-1]] >= aa[ii])
				st--;
			if (st == 0)
				RR[ii] = n;
			else
				RR[ii] = ss[st-1];
			
			ss[st++] = ii;
		}
		
		int res[] = new int[n+1];
		for (int ii = 0; ii < n; ii++) {
			int dd = RR[ii] - LL[ii] - 1;
			res[dd] = Math.max(res[dd], aa[ii]);
		}
		
		for (int ii = n-1; ii >= 1; ii--) {
			res[ii] = Math.max(res[ii], res[ii+1]);
		}
		
		for (int ii = 0; ii < n-1; ii++) {
			wr.print(res[ii+1]);
			wr.print(' ');
		}
		wr.print(res[n]);
		wr2.endl();
    }
	
    public static void run_slow()
    {
		int n = reader.nextInt();
		int aa[] = new int[n];
		
		for (int i = 0; i < n; i++)
			aa[i] = reader.nextInt();
		
		int bb[] = new int[n];
		for(int i = 0; i < n; i++)
			bb[i] = aa[i];


		for (int i = 0; i < n; i++)
		{
			int g = n - i;

			int max = -1;
			for (int j = 0; j < g; j++)
			{
				if (aa[j+i] < bb[j])
					bb[j] = aa[j+i];
				if (bb[j] > max)
					max = bb[j];
			}
		
			if (i > 0)
				wr.print(' ');
			wr.print(max);
		}
		

		wr2.endl();
	}

    
    static public PrintWriter wr; 
    static OutputWriter wr2=new OutputWriter(System.out);
	static class reader{
		static BufferedReader br; static StringTokenizer tkn;
		static String readln() { try { return br.readLine(); } catch (Exception e) { return ""; } }
		static void init(boolean console) {
			if (console) { br=new BufferedReader(new InputStreamReader(System.in)); }
			else { try { br=new BufferedReader(new InputStreamReader(new FileInputStream("input.txt"))); }
				catch (Exception e) { System.exit(551); } }
			tkn=new StringTokenizer("");
		}
		static String next() { while (!tkn.hasMoreTokens()){ tkn=new StringTokenizer(readln()); } return tkn.nextToken(); }
		static int nextInt(){ while (!tkn.hasMoreTokens()){ tkn=new StringTokenizer(readln()); } return Integer.parseInt(tkn.nextToken()); }
		static long nextLong(){ while (!tkn.hasMoreTokens()){ tkn=new StringTokenizer(readln()); } return Long.parseLong(tkn.nextToken()); }
		static double nextDouble(){ while (!tkn.hasMoreTokens()){ tkn=new StringTokenizer(readln()); } return Double.parseDouble(tkn.nextToken()); }
	}
    static class OutputWriter {
        OutputWriter(OutputStream stream) { wr = new PrintWriter(stream); }
        public void printf(String format, Object... args) { wr.print(String.format(Locale.ENGLISH, format, args)); }
        public void endl() { wr.print("\n"); }
    }
}
