#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define ll long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define pii pair<int, int>
using namespace std;
int mas[200001];
bool test[200001];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, s, b;
cin >> n;
vector<pii> mas;
for(int i=1; i<=n; i++)
{
int a;
cin >> a;
if(test[a]==0)
{
test[a]=1;
mas.pb({a, i});
}
else
{
while(mas.back().fi!=a)
{
test[mas.back().fi]=0;
mas.pop_back();
}
}
}
int x, y=0;
for(int i=0; i<n; i++)
{
if(y+1<mas.size() && i+1==mas[y+1].se)
y++;
x=mas[y].fi;
cout << x << endl;
}
return 0;
}