#include <iostream> #include <iomanip> #include <vector> #include <algorithm> #include <numeric> #include <functional> #include <cmath> #include <queue> #include <stack> #include <set> #include <map> #include <sstream> #include <string> #define repd(i,a,b) for (int i=(int)(a);i<(int)(b);i++) #define rep(i,n) repd(i,0,n) #define all(x) (x).begin(),(x).end() #define mod 1e9+7 #define inf 1<<32-1 #define mp make_pair #define pb push_back typedef long long ll; using namespace std; template <typename T> inline void output(T a, int p) { if(p) cout << fixed << setprecision(p) << a << "\n"; else cout << a << "\n"; } // end of template int main() { cin.tie(0); ios::sync_with_stdio(0); // source code int N; cin >> N; vector<int> A(N), L(N, -1), R(N, -1), B(N); rep(i, N){ cin >> A[i]; } set<int> s; rep(i, N){ if (s.find(A[i]) == s.end()) { L[i] = A[i]; s.insert(A[i]); } } s.erase(all(s)); for (int i = N - 1; i >= 0; i--) { if (s.find(A[i]) == s.end()) { R[i] = A[i]; s.insert(A[i]); } } s.erase(all(s)); rep(i, N){ if (L[i]) s.insert(L[i]); auto it = s.end(); it--; B[i] = *it; if (R[i]) s.erase(R[i]); } rep(i, N){ if (i) cout << " " << B[i]; else cout << B[i]; } cout << endl; return 0; }