#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
const ll MOD=1000000007;
int main(){
//ios_base::sync_with_stdio(false);
//cin.tie(nullptr);
ll n;
cin >> n;
vector<ll> lst(n+1);
map<ll,ll> Reference;
for(ll i=1;i<=n;i++){
cin >> lst[i];
Reference[lst[i]]=0;
}
stack<vector<ll>> OrderLst;
for(ll i=1;i<=n;i++){
ll Curr=lst[i];
if(OrderLst.empty()){
OrderLst.push({Curr,i,i});
Reference[Curr]=1;
continue;
}
vector<ll> Last=OrderLst.top();
if(Last[0]==Curr){
Last[2]=i;
}
else if(Reference[Curr]==0){
OrderLst.push({Curr,i,i});
Reference[Curr]=1;
}
else{
while(!OrderLst.empty() and OrderLst.top()[0]!=lst[i]){
Reference[OrderLst.top()[0]]=0;
OrderLst.pop();
}
OrderLst.top()[2]=i;
}
}
vector<ll> ans(n+1);
while(!OrderLst.empty()){
vector<ll> Curr=OrderLst.top();
OrderLst.pop();
for(ll i=Curr[1];i<=Curr[2];i++){
ans[i]=Curr[0];
}
}
for(ll i=1;i<=n;i++){
cout << ans[i] << "\n";
}
}