#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int n; cin >> n;
vector<int> a(n + 1), b(n + 1), pos;
map<int, int> cnt;
for(int i = 1; i <= n; i++){
cin >> a[i];
while(cnt[a[i]] && !pos.empty() && a[pos.back()] != a[i]){
cnt[a[pos.back()]]--;
pos.pop_back();
}
b[i] = (pos.empty() ? 0 : pos.back());
pos.push_back(i);
cnt[a[i]]++;
}
for(int i = n; i >= 1; i = b[i]){
for(int j = i; j > b[i]; j--) a[j] = a[i];
}
for(int i = 1; i <= n; i++) cout << a[i] << "\n";
}