#include #include #include #include //#include #include #include #include #include #include //#include #include #include #include //#include #include #include //#include #include #include #include #include const int dx[] = {1, 0, -1, 0}; const int dy[] = {0, 1, 0, -1}; using namespace std; typedef long long ll; typedef vector vi; typedef vector vll; typedef pair pii; const int MAXN = 100010; int ans[MAXN]; int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; map M; for (int i = 0; i < n; i++) { int a; cin >> a; if (M.find(a) == M.end()) { M[a].first = i; M[a].second = i; } else { M[a].first = min(M[a].first, i); M[a].second = max(M[a].first, i); } } set S; for (int i = 0; i < n; i++) S.insert(i); for (auto it = M.rbegin(); it != M.rend(); it++) { pii p = (*it).second; for (auto ite = S.lower_bound(p.first); ite != S.end() && (*ite) <= p.second; ) { ans[(*ite)] = (*it).first; ite = S.erase(ite); } } for (int i = 0; i < n; i++) { cout << ans[i]; if (i < n-1) cout << " "; } cout << endl; return 0; }