#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0)->sync_with_stdio(0);
int n;
cin >> n;
stack<tuple<int, int, int>> s;
vector<int> ans(n+2, 0);
map<int, int> mp;
for(int i=1; i<=n; i++) {
int a;
cin >> a;
if(mp[a] == 0) {
s.push({i, i, a});
} else {
while(!s.empty() && get<2>(s.top()) != a) {
mp[get<2>(s.top())]--;
s.pop();
}
if(s.empty()) s.push({1, i, a});
else s.push({get<1>(s.top())+1, i, a});
}
mp[a]++;
}
while(!s.empty()) {
for(int i=get<0>(s.top()); i<=get<1>(s.top()); i++) ans[i] = get<2>(s.top());
s.pop();
}
for(int i=1; i<=n; i++) cout << ans[i] << "\n";
return 0;
}