#include using namespace std; const long long N = 1e5 + 5, inf = 4e18, mod = 998244353; long long n, a[N], b[N], ans[N], one[N]; map st, ed; map vis, no; priority_queue q; int main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); cin >> n; for (long long i = 1; i <= n; ++i) { cin >> a[i]; if (!st[a[i]]) { st[a[i]] = i; } } for (long long i = n; i >= 1; --i) { if (!ed[a[i]]) { ed[a[i]] = i; } } sort(a + 1, a + n + 1); for (long long i = 1; i <= n; ++i) { b[st[a[i]]] = a[i], b[ed[a[i]]] = a[i]; if (st[a[i]] == ed[a[i]]) { one[a[i]] = 1; } } // for (long long i = 1; i <= n; ++i) { // cout << b[i] << ' '; // } // cout << '\n'; for (long long i = 1; i <= n; ++i) { if (b[i]) { if (!vis[b[i]]) { q.push(b[i]); } } while (!q.empty() && no[q.top()]) { q.pop(); } cout << q.top() << ' '; if (b[i] && vis[b[i]]) { no[b[i]] = 1; } if (b[i] && !vis[b[i]]) { vis[b[i]] = 1; } if (one[b[i]]) { no[b[i]] = 1; } } return 0; }