#include <algorithm>
#include <iostream>
using namespace std;
const int MAX = 1000005;
pair<int, int> p[MAX];
int par[MAX], size[MAX], ans[MAX];
bool mark[MAX];
int find(int v)
{
return (par[v] == v ? v : par[v] = find(par[v]));
}
void merge(int u, int v)
{
u = find(u);
v = find(v);
par[u] = v;
size[v] += size[u];
}
int main()
{
ios::sync_with_stdio(false);
for (int i = 0; i < MAX; i++)
{
par[i] = i;
size[i] = 1;
}
int n;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> p[i].first;
p[i].second = i;
}
sort(p, p + n, greater<pair<int, int> >());
int cur = 1;
for (int i = 0; i < n; i++)
{
int pos = p[i].second;
int val = p[i].first;
mark[pos] = true;
if (pos && mark[pos - 1])
merge(pos, pos - 1);
if (pos < n - 1 && mark[pos + 1])
merge(pos, pos + 1);
int sz = size[find(pos)];
while (cur <= sz)
ans[cur++] = val;
}
for (int i = 1; i <= n; i++)
cout << ans[i] << " ";
cout << endl;
return 0;
}
I2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwpjb25zdCBpbnQgTUFYID0gMTAwMDAwNTsKcGFpcjxpbnQsIGludD4gcFtNQVhdOwppbnQgcGFyW01BWF0sIHNpemVbTUFYXSwgYW5zW01BWF07CmJvb2wgbWFya1tNQVhdOwppbnQgZmluZChpbnQgdikKewoJcmV0dXJuIChwYXJbdl0gPT0gdiA/IHYgOiBwYXJbdl0gPSBmaW5kKHBhclt2XSkpOwp9CnZvaWQgbWVyZ2UoaW50IHUsIGludCB2KQp7Cgl1ID0gZmluZCh1KTsKCXYgPSBmaW5kKHYpOwoJcGFyW3VdID0gdjsKCXNpemVbdl0gKz0gc2l6ZVt1XTsKfQppbnQgbWFpbigpCnsKCWlvczo6c3luY193aXRoX3N0ZGlvKGZhbHNlKTsKCWZvciAoaW50IGkgPSAwOyBpIDwgTUFYOyBpKyspCgl7CgkJcGFyW2ldID0gaTsKCQlzaX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