#include <bits/stdc++.h>
#define fio ios_base::sync_with_stdio(0);cin.tie(0);
#define ll long long
#define pb push_back
#define fi first
#define se second
#define en exit(0);
using namespace std;
const int N = 2e5 + 5;
const int INF = 1e9 + 5;
int a[N];
bool has_repainted(set<pair<int,int> > &s, int p)
{
// check if position p has been repainted by another colour
auto t = s.lower_bound({p + 1, -1});
assert(t != s.begin());
t--;
int l = (*t).fi, r = (*t).se;
assert(l <= p && p <= r);
return (a[l] != a[p]);
}
int main()
{
fio
// ifstream cin("in.in");
map<int,stack<int> > pos; // val -> {positions not checked containing this value}
set<pair<int,int> > s; // a set of intervals {l,r} with colour equal to a[l]
int n;
cin >> n;
for(int i = 1;i <= n;i++)
{
cin >> a[i];
auto &t = pos[a[i]];
while(!t.empty() && has_repainted(s, t.top()))
t.pop();
int l = i, r = i;
if(!t.empty())
{
l = t.top();
// delete all intervals [l';r'], where l' >= l
auto t = s.lower_bound({l, -1});
while(t != s.end())
{
s.erase(t);
t = s.lower_bound({l, -1});
}
}
s.insert({l, r});
t.push(i);
}
for(auto x : s)
for(int i = x.fi;i <= x.se;i++)
cout << a[x.fi] << " ";
return 0;
}