import std.stdio;
import std.algorithm;
import std.string;
import std.range;
import std.array;
import std.conv;
import std.complex;
import std.math;
import std.ascii;
import std.bigint;
import std.container;
import std.typecons;

auto readInt() {
	return readInts()[0];
}
auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readLong() { 
	return readLongs()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}

void main() {
	auto n = readInt();
	auto a = readLongs();
	auto arev = a.dup;
	arev.reverse;
	a = -1 ~ a;
	arev = -1 ~ arev;
	int[] s = [0];
	auto t = new int[](n);
	auto u = new int[](n);
	foreach(i; 0..n) {
		while(!(a[s[$-1]] < a[i+1])) {
			s = s[0..$-1];
		}
		t[i] = i-s[$-1];
		s ~= i+1;
	}
	s = [0];
	foreach(i; 0..n) {
		while(!(arev[s[$-1]] < arev[i+1])) {
			s = s[0..$-1];
		}
		u[n-i-1] = i-s[$-1];
		s ~= i+1;
	}
	auto si = new long[](n);
	foreach(i; 0..n) {
		auto l = t[i]+u[i]+1;
		si[l-1] = max(si[l-1], a[i+1]);
	}
	foreach_reverse(i; 0..n-1) {
		si[i] = max(si[i+1], si[i]);
	}
	foreach(i; 0..n) {
		writeln(si[i]);
	}
}






