#include <bits/stdc++.h>
using namespace std;
int main(){
cin.tie(nullptr)->sync_with_stdio(false);
int n; cin >> n;
map<int, int> cnt;
stack<array<int, 3>> stk;
vector<int> res(n + 1);
for(int i = 1; i <= n; ++i){
int a; cin >> a;
if(!cnt[a]){
cnt[a]++;
stk.push({a, i, i});
continue;
}
while(!stk.empty() && stk.top()[0] != a){
cnt[stk.top()[0]]--;
stk.pop();
}
stk.push({a, stk.top()[2] + 1, i});
cnt[a]++;
}
while(!stk.empty()){
auto [a, l, r] = stk.top(); stk.pop();
for(int i = l; i <= r; ++i) res[i] = a;
}
for(int i = 1; i <= n; ++i) cout << res[i] << '\n';
}