#include #include #ifdef LOCAL #include #define debug(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__) #else #define debug(...) (static_cast(0)) #endif using namespace atcoder; using mint=modint1000000007; using namespace std; using ll=long long; using ul=unsigned long long; int dx[8] = {1, 0, -1, 0, -1, -1, 1, 1}; int dy[8] = {0, 1, 0, -1, -1, 1, -1, 1}; using Graph=vector>; int main(){ int N; ll X; cin>>N>>X; setst; vectorC(N+1); for(int i=0;i<=N;i++)st.insert(i); queueA; for(int i=0;i>a; if(a<=N)C[a]++; A.push(a); st.erase(a); if(X-1==i){cout<ans; int mex=0; for(int i=0;i<=N;i++)if(C[i]==0){mex=i;break;} ans.push_back(mex); A.push(mex); C[mex]++; st.erase(mex); if(A.front()<=N){ C[A.front()]--; if(C[A.front()]==0)st.insert(A.front()); } A.pop(); while(true){ mex=*st.begin(); ans.push_back(mex); A.push(mex); C[mex]++; st.erase(mex); if(A.front()<=N){ C[A.front()]--; if(C[A.front()]==0)st.insert(A.front()); } A.pop(); if(ans[0]==ans.back()){ans.pop_back();break;} } cout<