#include #include #include typedef long long ll; using namespace std; int main() { int n, i; cin >> n; vector a(n), b(n); map> rng; for (i = 0; i < n; ++i) { cin >> a[i]; } for (i = 0; i < n; ++i) { auto it = rng.find(a[i]); if (it == rng.end()) { rng[a[i]] = make_pair(i, i); } else { it->second.second = i; } } for (auto p: rng) { auto lr = p.second; for (i = lr.first; i <= lr.second; ++i) { b[i] = p.first; } } cout << b[0]; for (i = 1; i < n; ++i) { cout << ' ' << b[i]; } cout << endl; return 0; }