// Born_To_Laugh - Hughie Do
#include <bits/stdc++.h>
#define alle(AC) AC.begin(), AC.end()
#define fi first
#define se second
using namespace std;
typedef long long ll;
[[maybe_unused]] const int MOD = 998244353, INF = 1e9 + 7;
const int maxn = 2e5 + 10;
vector<int> st;
int n;
int a[maxn];
map<int, int> cnt;
void solve(){
cin >> n;
for(int i=1; i<=n; ++i) cin >> a[i];
for(int i=1; i<=n; ++i){
if(cnt[a[i]] == 0){
st.push_back(i);
cnt[a[i]]++;
continue;
}
while(!st.empty() && a[st.back()] != a[i]){
cnt[a[st.back()]]--;
st.pop_back();
}
st.push_back(i);
cnt[a[i]]++;
}
for(int i=0; i<st.size(); ++i){
int j = (i != (st.size() - 1)) ? st[i + 1] : n + 1;
for(int sth = st[i]; sth < j; ++sth){
cout << a[st[i]] << ' ';
}
}
}
signed main(){
// freopen("inp.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
solve();
}