#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; #define rep(i,n) for(int i=0;i=0;i--) #define all(a) a.begin(),a.end() #define mp(a,b) make_pair(a,b) #define pb(a) push_back(a) #define SS stringstream #define DBG1(a) rep(_X,sz(a)){printf("%d ",a[_X]);}puts(""); #define DBG2(a) rep(_X,sz(a)){rep(_Y,sz(a[_X]))printf("%d ",a[_X][_Y]);puts("");} #define bitcount(b) __builtin_popcount(b) #define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i) int main(){ int n; cin >> n; map mi; map mx; for(int i = 0 ; i < n ; i++){ int a; cin >> a; if( !mi.count(-a) ){ mi[-a] = i; } mx[-a] = i; } set v; for(int i = 0 ; i < n ; i++) v.insert(i); v.insert(1e9); vector res(n,-1); for( auto a : mx ){ int x = a.first; int mxx = mx[x]; //cout << mi[x] << " " << mx[x] << endl; while(1){ auto it = v.lower_bound(mi[x]); if( *it <= mxx ){ res[*it] = -x; v.erase(*it); }else{ break; } } } for(int i = 0 ; i < n ; i++) cout << res[i] << (i+1==n?"\n":" "); }