#pragma GCC optimize ("Ofast") #include using namespace std; inline void rd(int &x){ int k, m=0; x=0; for(;;){ k = getchar_unlocked(); if(k=='-'){ m=1; break; } if('0'<=k&&k<='9'){ x=k-'0'; break; } } for(;;){ k = getchar_unlocked(); if(k<'0'||k>'9'){ break; } x=x*10+k-'0'; } if(m){ x=-x; } } inline void wt_L(char a){ putchar_unlocked(a); } inline void wt_L(int x){ char f[10]; int m=0, s=0; if(x<0){ m=1; x=-x; } while(x){ f[s++]=x%10; x/=10; } if(!s){ f[s++]=0; } if(m){ putchar_unlocked('-'); } while(s--){ putchar_unlocked(f[s]+'0'); } } int N; int X; int res[100000]; int r; void push(int a = 0, int b = 0, int c = 0, int d = 0){ if(a){ res[r++] = a; } if(b){ res[r++] = b; } if(c){ res[r++] = c; } if(d){ res[r++] = d; } } int main(){ int i, k, m; rd(N); rd(X); m = (N-1) / 4; k = 4; for(i=0;i<(m);i++){ if(X/4==k/4){ k += 4; } push(k, k+1, k+2, k+3); k += 4; } if(N%4==0){ if(X==1){ push(k+1, k+3, 1, 2); } else if(X==2){ push(k, k+1, 1, 2); } else if(X==3){ push(k, k+1, 1, 3); } else{ push(X, 1, 2, 3); } } if(N%4==1){ push(X); } if(N%4==2){ if(X!=1){ push(X^1, 1); } else{ push(2, 3); } } if(N%4==3){ if(X==1){ push(3, k, k+2); } else if(X==2){ push(3, k, k+1); } else if(X==3){ push(2, k, k+1); } else{ push(X^1, 2, 3); } } for(i=0;i<(N);i++){ wt_L(res[i]); wt_L('\n'); } return 0; } // cLay varsion 20190820-1 // --- original code --- // int N, X; // int res[1d5], r; // // void push(int a = 0, int b = 0, int c = 0, int d = 0){ // if(a) res[r++] = a; // if(b) res[r++] = b; // if(c) res[r++] = c; // if(d) res[r++] = d; // } // // { // int i, k, m; // rd(N,X); // // m = (N-1) / 4; // k = 4; // rep(i,m){ // if(X/4==k/4) k += 4; // push(k, k+1, k+2, k+3); // k += 4; // } // // if(N%4==0){ // if(X==1) push(k+1, k+3, 1, 2); // else if(X==2) push(k, k+1, 1, 2); // else if(X==3) push(k, k+1, 1, 3); // else push(X, 1, 2, 3); // } // if(N%4==1){ // push(X); // } // if(N%4==2){ // if(X!=1) push(X^1, 1); // else push(2, 3); // } // if(N%4==3){ // if(X==1) push(3, k, k+2); // else if(X==2) push(3, k, k+1); // else if(X==3) push(2, k, k+1); // else push(X^1, 2, 3); // } // // rep(i,N) wt(res[i]); // }