#include "bits/stdc++.h" using namespace std; #define DEBUG(x) cout<<#x<<": "< #define vl vector #define vii vector< vector > #define vll vector< vector > #define vs vector #define pii pair #define pis pair #define psi pair #define pll pair const int inf = 1000000001; const ll INF = 1e18 * 2; #define MOD 1000000007 #define mod 1000000009 #define pi 3.14159265358979323846 #define Sp(p) cout<> n; int i, j; vi a(n); map left, right; set st; for (i = 0; i < n; i++) { cin >> a[i]; st.insert(a[i]); if (left[a[i]] == 0) { left[a[i]] = i + 1; } else { right[a[i]] = i + 1; } } vi b(n); for (auto itr = st.begin(); itr != st.end(); itr++) { int x = *itr; if (right[x]) { int l = left[x] - 1, r = right[x] - 1; b[l] = b[r] = x; } else { int l = left[x] - 1; b[l] = -x; } } //DEBUG_VEC(b); map state; priority_queue pq; vi ans(n); int now = -1; for (i = 0; i < n; i++) { if (b[i]) { int x = b[i]; if (x < 0) { if (now < abs(x)) { ans[i] = abs(x); } else { ans[i] = now; } continue; } if (state[x] == 0) { state[x]++; if (now < x) { pq.push(now); now = x; } else { pq.push(x); } ans[i] = now; } else if (state[x] == 1) { state[x]++; ans[i] = now; if (now == x) { now = pq.top(); pq.pop(); while (state[now] == 2) { now = pq.top(); pq.pop(); } } } } else { ans[i] = now; } } for (i = 0; i < n; i++) { cout << ans[i] << " "; } cout << endl; }