#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dbg(...) 47
#endif
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
auto b = a;
ranges::sort(b);
b.erase(unique(b.begin(), b.end()), b.end());
map<int, int> m;
for (int i = 0; i < n; i++) {
int x = ranges::lower_bound(b, a[i]) - b.begin();
m[x] = a[i];
a[i] = x;
}
vector<int> f(n, -1);
set<array<int, 2>> s;
for (int i = 0; i < n; i++) {
if (f[a[i]] == -1) {
f[a[i]] = i;
s.insert({i, a[i]});
} else {
int k = f[a[i]];
while (true) {
auto it = s.lower_bound({k + 1, 0});
if (it == s.end()) break;
f[(*it)[1]] = -1;
s.erase(it);
}
}
}
vector<array<int, 2>> v;
for (auto [x, y] : s) {
v.push_back({x, m[y]});
}
int pos = 0;
for (int i = 0; i < v.size() - 1; i++) {
while (pos < v[i + 1][0]) {
cout << v[i][1] << ' ';
pos++;
}
}
while (pos < n) {
cout << v.back()[1] << ' ';
pos++;
}
cout << '\n';
return 0;
}