Problem:
 Score : 600 points    Problem Statement Construct a sequence a = { a_1,\ a_2,\ ...,\ a_{2^{M + 1}} } of length 2^{M + 1} that satisfies the following conditions, if such a sequence exists.   Each integer between 0 and 2^M - 1 (inclusive) occurs twice in a .  For any i and j  (i < j) such that a_i = a_j , the formula a_i \ xor \ a_{i + 1} \ xor \ ... \ xor \ a_j = K holds.    What is xor (bitwise exclusive or)?  The xor of integers c_1, c_2, ..., c_n is defined as follows:   When c_1 \ xor \ c_2 \ xor \ ... \ xor \ c_n is written in base two, the digit in the 2^k 's place ( k \geq 0 ) is 1 if the number of integers among c_1, c_2, ...c_m whose binary representations have 1 in the 2^k 's place is odd, and 0 if that count is even.   For example, 3 \ xor \ 5 = 6 . (If we write it in base two: 011  xor  101  =  110 .)

Solution (Python):
from itertools import permutations
import sys

sys.setrecursionlimit(10 ** 6)
from bisect import *
from collections import *
from heapq import *

def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def SI(): return sys.stdin.readline()[:-1]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
int1 = lambda x: int(x) - 1
def MI1(): return map(int1, sys.stdin.readline().split())
def LI1(): return list(map(int1, sys.stdin.readline().split()))
p2D = lambda x: print(*x, sep="\n")
dij = [(1, 0), (0, 1), (-1, 0), (0, -1)]

def main():
    m,k=MI()
    if (m,k)==(1,1) or k>=2**m:ans=[-1]
    elif k==0:
        ans=list(range(1<<m))
        ans+=ans[::-1]
    else:
        ans=[]
        for i in range(1<<m):
            if i==k:continue
            ans.append(i)
        rev=ans[::-1]
        ans.append(k)
        ans+=rev
        ans.append(k)
    print(*ans)

main()

Solution (Python):
M, K = map(int, input().split())
if K >= 2**M:
    print(-1)
elif M == 1:
    if K == 0:
        print(0, 0, 1, 1)
    else:
        print(-1)
else:
    a = list(range(K)) + list(range(K+1, 2**M))
    ans = a[::-1] + [K] + a + [K]
    print(*ans)

Solution (Python):
m, k = map(int, input().split())

if 2**m <= k:
    print(-1)

elif m == 0:
    if k == 0:
        print(0, 0)
    else:
        print(-1)

elif m == 1:
    if k == 0:
        print(0,0,1,1)
    else:
        print(-1)

else:
    b = [i for i in range(2**m) if i != k]
    ans = b + [k] + b[::-1] + [k]
    print(*ans)

Solution (Python):
import sys
input = sys.stdin.readline

M,K = map(int,input().split())

if M==1:
    if K==0:
        print(0,0,1,1)
    else:
        print(-1)
else:
    if K >= (1<<M):
        print(-1)
    else:
        a = list(range(1<<M))
        a.remove(K)
        ans = a + [K] + a[::-1] + [K]
        print(" ".join(map(str,ans)))

Solution (Python):
m, k = map(int, input().split())
if k >= 2**m:
  print(-1)
  exit()
if m == 0:
  print(0, 0)
elif m == 1:
  if k == 0:
    print(0, 1, 1, 0)
  else:
    print(-1)
else:
  b = [i for i in range(2**m) if i != k]
  c = b[::-1]
  A = b + [k] + c + [k]
  print(*A)

Solution (Python):
M, K = map(int, input().split())

if M == 0:
  if K == 0:
    print(0, 0)
  else:
    print(-1)
elif M == 1:
  if K == 0:
    print(0, 0, 1, 1)
  else:
    print(-1)
elif K < (1 << M):
  for i in range(1 << M):
    if i != K:
      print(i, end=" ")
  print(K, end=" ")
  for i in range((1 << M) - 1, -1, -1):
    if i != K:
      print(i, end=" ")
  print(K)
else:
  print(-1)

Solution (Python):
import bisect
import sys


input = sys.stdin.readline
sys.setrecursionlimit(100000)


class v:
    def __init__(self, f):
        self.f = f
        self.v = None

    def __str__(self):
        return str(self.v)

    def ud(self, n):
        if self.v is None:
            self.v = n
        else:
            self.v = self.f(self.v, n)


def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def main():
    M, K = read_values()
    if K >= 2 ** M:
        print(-1)
        return

    if M == 1:
        print("0 0 1 1" if K == 0 else -1)
        return

    X = [str(i) for i in range(2 ** M) if i != K]
    res = X + [str(K)] + X[::-1] + [str(K)]
    print(" ".join(res))


if __name__ == "__main__":
    main()

Solution (Python):
m,k=map(int,input().split())
if k>=2**m:
    print(-1)
elif m==1:
    if k==0: print(0,0,1,1)
    else: print(-1)
else:
    tmp=k
    for i in range(1,2**m):
        tmp^=i
    ans=[i for i in range(2**m) if i!=k]+[k]+[i for i in range(2**m-1,-1,-1) if i!=k]+[k]
    print(*ans)

Solution (Python):
m,k=map(int,input().split())
if k>=2**m:
    print(-1)
elif m==0: print(0,0)
elif m==1:
    if k==0: print(0,0,1,1)
    else: print(-1)
else:
    tmp=k
    for i in range(1,2**m):
        tmp^=i
    ans=[i for i in range(2**m) if i!=k]+[k]+[i for i in range(2**m-1,-1,-1) if i!=k]+[k]
    print(*ans)

Solution (Python):
m, k = map(int, input().split())

if k >= 2**m:
    print(-1)
    exit()

if m == 0:
    print(0, 0)
    exit()
if m == 1:
    if k == 0:
        print(0, 0, 1, 1)
        exit()
    else:
        print(-1)
        exit()

A = [k]
for i in range(2**m):
    if i == k:
        continue
    A.append(i)
A.append(k)
for i in range(2**m - 1, -1, -1):
    if i == k:
        continue
    A.append(i)

print(*A)

Solution (Python):
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))



from collections import deque

M,K = LI()

if M == 0:
    if K == 0:
        print(0,0)
    else:
        print(-1)
    exit()

if M == 1:
    if K == 0:
        print(0,0,1,1)
    else:
        print(-1)
    exit()

if K >= 2**M:
    print(-1)
else:
    A = deque([K])
    for i in range(2**M):
        if i == K:
            continue
        else:
            A.appendleft(i)
            A.append(i)
    A.append(K)
    print(*A)

Solution (Python):
m,k = map(int,input().split())
if m == 0:
    if k == 0:
        print(0,0)
    else:
        print(-1)
    exit()
if m == 1:
    if k== 0:
        print(0,0,1,1)
    else:
        print(-1)
    exit()
if k < 2**m:
    l = [i for i in range(2**m) if i != k ]
    l = l + [k] + l[::-1] + [k]
    print(*l)
else:
    print(-1)

Solution (Python):
def xor_matching(M, K):
    
    if M == 0:
        return [0, 0] if K == 0 else [-1]
    if M == 1:
        return [0, 1, 1, 0] if K == 0 else [-1]

    if K >= (1 << M):
        return [-1]

    values = list(range(1 << M))
    Amax = values[-1]
    res = []
    res.append(K)
    for v in values:
        if v == K:
            continue
        res.append(v)
    res.append(K)
    for v in values[::-1]:
        if v == K:
            continue
        res.append(v)
    return res


if __name__ == "__main__":
    M, K = map(int, input().split())
    ans = xor_matching(M, K)
    print(*ans)

Solution (Python):
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

M, K = lr()

if 2**M <= K or (M == 1 and K == 1):
    print(-1); exit()

if K == 0:
    answer = [x//2 for x in range(2**(M+1))]

else:
    answer = []
    A = [x for x in range(2**M) if x != K]
    answer.extend(A)
    if K != 0:
        answer.append(K)
    answer.extend(A[::-1])
    if K != 0:
        answer.append(K)

print(*answer)

Solution (Python):
def main():
    M,K=map(int, input().split())
    ans=[-1]
    if M==0:
        if K==0:
            ans=[0,0]
    elif M==1:
        if K==0:
            ans=[0,0,1,1]
    else:
        if K<(1<<M):
            L=[i for i in range(1<<M) if i!=K]
            ans=[K]+L+[K]+L[::-1]
    print(*ans)

if __name__ == "__main__":
    main()

Solution (Python):
m,k=map(int,input().split())
if k<=2**m-1 and m>1:
    lists=[]
    for i in range(2**m-1,-1,-1):
        if i!=k:
            lists.append(i)
    lists.append(k)
    for i in range(2**m):
        if i!=k:
            lists.append(i)
    lists.append(k)
    print(*lists)
elif k<=2**m-1 and m==0:
    print(*[0,0])
    
elif k<=2**m-1 and m==1:
    if k==0:
        print(*[0,0,1,1])
    elif k==1:
        print(-1)

else:
    print(-1)

Solution (Python):
M, K = map(int, input().split())

if K==0:
    l = []
    for i in range(2**M):
        l += [i, i]
    print(*l)
elif M==0 or M==1:
    print(-1)
elif 1<=K<2**M:
    l = []    
    for i in range(2**M):
        if i!=K:
            l += [i]
    l += [K]
    for i in range(2**M)[::-1]:
        if i!=K:
            l += [i]
    l += [K]
    print(*l)
else:
    print(-1)

Solution (Python):
m,k=map(int,input().split())
if k>=2**m or m==k==1:
	print(-1)
elif m==1:
	print("1 1 0 0")
else:
	l=list(range(k))+list(range(k+1,2**m))
	print(*(l+[k]+l[::-1]+[k]))

Solution (Python):
M,K = map(int,input().split())

if M == 0:
    if K == 0:
        print(0,0)
    else:
        print(-1)
elif M == 1:
    if K == 0:
        print(0,0,1,1)
    else:
        print(-1)
else:
    if K == 0:
        A = [i//2 for i in range(2**(M+1))]
        print(*A)
    elif 0 < K < 2**M:
        A = []
        for i in range(K):
            A.append(i)
        for i in range(2**M-K-1):
            A.append(2**M-i-1)
        A.append(0)
        for i in range(2**M-K):
            A.append(K+i)
        for i in range(K-1):
            A.append(K-i-1)
        A.append(K)
        print(*A)
    else:
        print(-1)

Solution (Python):
import sys
input = sys.stdin.buffer.readline

def main():
    M,K = map(int,input().split())
    if M == 0:
        if K == 0:
            print(0,0)
        else:
            print(-1)
    elif M == 1:
        if K == 0:
            print(0,0,1,1)
        else:
            print(-1)
    else:
        if 2**M <= K:
            print(-1)
        else:
            use = [i for i in range(2**M)]
            use.pop(K)
            _use = list(reversed(use))
            ans = use+[K]+_use+[K]
            print(*ans)

if __name__ == "__main__":
    main()

Solution (Python):
M, K = map(int, input().split())
def binary_digits(n):
  cnt = 0
  while n != 0:
    cnt += 1
    n //= 2
  return cnt
if binary_digits(K) > M:
  print(-1)
else:
  if M == 1:
    if K == 1:
      print(-1)
    elif K == 0:
      print(0, 0, 1, 1)
  else:
    b = 2**(M+1)
    if K == 0:
      for i in range(b):
        if i != b - 1:
          print(i // 2, end = ' ')
        else:
          print(i // 2)
    else:
      A = [0 for i in range(b)]
      A[1], A[b//2+1] = K, K
      p = 1
      for i in range(1, b//2):
        if i != K:
          A[b//2-p+1], A[b//2+p+1] = i, i
          p += 1
      for i in range(b):
        if i != b - 1:
          print(A[i], end = ' ')
        else:
          print(A[i])

Solution (Python):
M, K = (int(i) for i in input().split())

if M == 1:
    if K == 0:
        print("0 0 1 1")
    else:
        print("-1")
else:
    N = 2**M
    if K >= N:
        print("-1")
    elif K == 0:
        l = list(range(N))
        ll = l + l[::-1]
        ll = [str(a) for a in ll]
        print(" ".join(ll))
    else:
        l = list(range(N))
        l = l[:K] + l[K+1:]
        ll = [0, K] + l + [K] + l[::-1][:-1]
        ll = [str(a) for a in ll]
        print(" ".join(ll))

Solution (Python):
m,k=map(int,input().split())
if k>2**m-1:
  print(-1)
elif k==0:
  ans=[i for i in range(2**m)]
  ans=ans+ans[::-1]
  print(*ans)
else:
  if m==1:
    print(-1)
  else:
    ans=[]
    for i in range(2**m):
      if i==k:
        continue
      ans.append(i)
    ans=[k]+ans+[k]+ans[::-1]
    print(*ans)

Solution (Python):
def main():
    M, K = map(int, input().split())
    if M == 1:
        if K == 0:
            print('0 0 1 1')
            return
        if K == 1:
            print('-1')
            return
    if (2**M) - 1 < K:
        print('-1')
        return
    l = [i for i in range(K)] + [i for i in range(K+1, (2**M))] + [K] + [i for i in reversed(range(K+1, (2**M)))] + [i for i in reversed(range(K))] + [K]
    print(' '.join(str(i) for i in l))
main()

Solution (Python):
def main():
    M, K = map(int, input().split())
    if M == 1:
        if K == 0:
            print('0 0 1 1')
        else:
            print('-1')
        return
    if K >= 2 ** M:
        print(-1)
        return
    r = []
    for i in range(2 ** M):
        if i != K:
            r.append(i)
    r.append(K)
    for i in reversed(range(2 ** M)):
        if i != K:
            r.append(i)
    r.append(K)
    print(' '.join(str(i) for i in r))
main()

Solution (Python):
m,k=map(int,input().split())
if m==1:
  if k!=0:
    print(-1)
  else:
    print(0,0,1,1)
  exit()
elif 2**m<=k:
  print(-1)
  exit()
b=[]
for i in range(2**m):
  if i!=k:
    b.append(i)
c=b[::-1]
d=b+[k]+c+[k]
print(*d)

Solution (Python):
m, k = map(int, input().split())
if m == 1 and k == 1:
    print(-1)
elif m == 1 and k == 0:
    print("0 0 1 1")
elif 2**m > k:
    ans = str(k)
    y = []
    for i in range(2**m):
        if i == k:
            continue
        y.append(str(i))
    ans =  ' '.join(reversed(y)) + ' ' + ans + ' ' + ' '.join(y) + ' ' +ans
    print(ans)
else:
    print(-1)

Solution (Python):
def power(n, m):
    ret = 1
    for i in range(m):
        ret *= n
    return ret

M, K = map(int, input().split())
if K >= power(2, M):
    print(-1)
else:
    if M == 0:
        print(0, 0)
    elif M == 1:
        if K == 1:
            print(-1)
        else:
            print(0, 0, 1, 1)
    else:
        ans = []
        N = power(2, M)
        if K % 2 == 1:
            ans.append(K)
            ans.append(K - 1)
            for i in range(0, N):
                if i == K or i == K - 1:
                    continue
                ans.append(i)
            ans.append(K)
            for i in range(N - 1, -1, -1):
                if i == K or i == K - 1:
                    continue
                ans.append(i)
            ans.append(K - 1)
        else:
            ans.append(K)
            ans.append(K + 1)
            for i in range(0, N):
                if i == K or i == K + 1:
                    continue
                ans.append(i)
            ans.append(K)
            for i in range(N - 1, -1, -1):
                if i == K or i == K + 1:
                    continue
                ans.append(i)
            ans.append(K + 1)
        print(" ".join(map(str, ans)))

Solution (Python):
m,k = map(int, input().split())

if( k >= 2**m):
    print(-1)
    exit()

if( (m==1) & (k==1) ):
    print(-1)
    exit()


n = 2**(m+1)
ans = [0] * n
if( k==0):
    for i in range(n):
        ans[i] = i//2
    print(' '.join([str(i) for i in ans ]))
    exit()

ans[0] = k
ind = 1
for i in range(n//2):
    if(i != k):
        ans[ind] = i
        ind += 1

ans[ind] = k
ind += 1

for i in range(n//2 -1, -1, -1):
    if(i != k):
        ans[ind] = i
        ind += 1


print(' '.join([str(i) for i in ans ]))

Solution (Python):
M, K = map(int,input().split())
if M==1:
  if K!=0:
    print(-1)
  else:
    print(0,0,1,1)
elif K>=2**M:
  print(-1)
else:
  b = [i for i in range(K)] + [i for i in range(K+1,2**M)]
  c = b[::-1]
  ans = b+[K]+c+[K]
  print(*ans)

Solution (Python):
M, K = map(int, input().split())

ans = [-1]
if M == 1:
  if K == 0:
    ans = [0, 0, 1, 1]
else:
  if K < 2**M:
    b = [i for i in range(2**M) if i != K]
    ans = b + [K] + b[::-1] + [K]

print(*ans)

Solution (Python):
def main():
  M,K=map(int,input().split())
  if K == 0:
    ans = []
    for i in range(2**M):
        ans.extend([i, i])
    print(*ans)
    return 0
  if 2**M <= K:
    print(-1)
    return 0
  if M==1:
    if K==1:
      print(-1)
      return 0

  ans=[str(x) for x in range(2**M) if x!=K]
  ans_b=[str(x) for x in range(2**M-1,-1,-1) if x!=K]
  print(str(K)+" "+" ".join(ans)+" "+str(K)+" "+" ".join(ans_b))
main()

Solution (Python):


def solve(M,K):
    if K>=2**M:
        return False
    if M==0:
        if K==0:
            return ["0","0"]
        else:
            return False
    elif M==1:
        if K==1:
            return False
        else:
            return ["0","0","1","1"]
    else:
        b=list(range(2**M))
        b.remove(K)
        import copy
        c=copy.deepcopy(b)
        c.reverse()
        return b+[K]+c+[K]

if __name__ == '__main__':
    M,K=list(map(int,input().split()))
    ans=solve(M,K)
    if ans is False:
        print(-1)
    else:
        for i in range(len(ans)):
            if i!=len(ans):
                print("{} ".format(ans[i]),end="")
            else:
                print(ans[i])

Solution (Python):
M, K = map(int, input().split())

answer = []
if K == 0:
  for i in range(2 ** M):
    answer.append(i)
    answer.append(i)
  print(*answer)
  exit()

if K >= 2 ** M:
  print(-1)
  exit()
  
tmp = 0
for i in range(2 ** M):
  if i != K:
    tmp ^= i
if tmp != K:
  print(-1)
else:
  tmp_arr = []
  for i in range(1, 2 ** M):
    if i != K:
      tmp_arr.append(i)
  answer = tmp_arr + [K] + tmp_arr[::-1] + [0, K, 0]
  print(*answer)

Solution (Python):
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True 
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

m,k = inm()
if m==0 and k==0:
    print('0 0')
    exit()
if m==0 and k>0:
    print('-1')
    exit()
if m==1 and k==0:
    print('0 0 1 1')
    exit()
if m==1 and k>0:
    print('-1')
    exit()
if k>=2**m:
    print('-1')
    exit()

if k==0:
    printn('0 0')
    for i in range(1,2**m):
        printn(' {} {}'.format(i,i))
    print('')
    exit()

u = [False]*(2**m)
u[k] = True
a = []
cnt = 0
for i in range(1,2**m):
    j = i^k
    if not u[i] and not u[j]:
        a.append(i)
        u[j] = True
        cnt += 1
        if cnt==2**(m-1)-1:
            break

s = [x for x in a]
t = [x for x in a]
t.reverse()
s.extend([0,k,0])
s.extend(t)
v = [x^k for x in a]
t = [x for x in v]
t.reverse()
s.extend(v)
s.append(k)
s.extend(t)

printn(s[0])
for i in range(1,len(s)):
    printn(' ' + str(s[i]))
print("")

Solution (Python):
import sys
m,k=map(int,input().split())
if k>=2**m:
    print(-1)
    sys.exit()
if m==1:
    if k==0:
        xor=[0,0,1,1]
        print(' '.join(map(str,xor)))
    else:
        print(-1)
    sys.exit()
idx=0
xor=[0]*(2**(m+1))

for i in range(2**m-1):
    if idx==k:
        idx+=1
    xor[i]=idx
    idx+=1
xor[2**m-1]=k
idx=2**m-1
for i in range(2**m,2**(m+1)-1):
    if idx==k:
        idx-=1
    xor[i]=idx
    idx-=1
xor[-1]=k
print(' '.join(map(str,xor)))

Solution (Python):
m, k = map(int, input().split())
ret = []
if k >= 2 ** m or (m == 1 and k == 1):
    ret.append(-1)
elif m == 1:
    ret = [0, 0, 1, 1]
else:
    ret.append(k)
    for i in range(2 ** m):
        if i != k:
            ret.append(i)
    ret.append(k)
    for i in range(2 ** m - 1, -1, -1):
        if i != k:
            ret.append(i)
print(' '.join(map(str, ret)))

Solution (Python):
import math
import sys
import numpy as np
sys.setrecursionlimit(10 ** 7)

def int_input():
    return map(int, input().split())

m, k = int_input()
if k == 0:
    l = []
    for i in range(2 ** m):
        l.append(i)
    m = l[:]
    m.reverse()
    ans = m + l
    print(*ans)
else:
    v = 0
    l = []
    for i in range(2 ** m):
        if i != k:
            l.append(i)
            v ^= i
    m = l[:]
    m.reverse()
    ans = m + [k] + l + [k]
    if v == k: print(*ans)
    else: print(-1)

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    m,k = LI()
    if k == 0:
        print(*[i>>1 for i in range(1<<(m+1))])
        return
    if 1<<m <= k or m == k == 1:
        print(-1)
    else:
        ans = [k]+[i for i in range(1<<m) if i != k]+[k]+[i for i in range(1<<m)[::-1] if i != k]
        print(*ans)
    return


if __name__ == "__main__":
    solve()

Solution (Python):
M, K = map(int, input().split())
maxim = 2 ** M

if maxim <= K:
    print("-1")
else:
    if maxim == 1 and K == 0:
        print("0 0")
    elif maxim == 2:
        if K == 0:
            print("0 0 1 1")
        elif K == 1:
            print("-1")
    else:
        for i in range(maxim):
            if i != K:
                print(str(i), end=" ")
        print(str(K), end=" ")
        for i in range(maxim - 1, -1, -1):
            if i != K:
                print(str(i), end=" ")
        print(str(K))

Solution (Python):
M, K = map(int, input().split())
m = 1 << M

if K >= m:
    print(-1)
    exit()

if M == 0:
    print(0, 0)
    exit()

if M == 1:
    if K == 0:
        print(0, 0, 1, 1)
    else:
        print(-1)
    exit()

k = str(K)
seq = list(map(str, range(m)))
seq.remove(k)
answer = seq + [k] + seq[::-1] + [k]

print(' '.join(answer))

Solution (Python):


import sys
import copy

M, K = (int(x) for x in input().split())

if K >= 2 ** M:
	print("-1")
	sys.exit()

if M == 0:
	print("0 0")
	sys.exit()

if M == 1:
	if K == 0:
		print("0 0 1 1")
		sys.exit()
	else:
		print("-1")
		sys.exit()

b = [x for x in range(2 ** M) if x != K]
c = list(reversed(copy.copy(b)))

for x in b:
	print(x, end = " ")

print(str(K), end = " ")

for x in c:
	print(x, end = " ")

print(str(K))

Solution (Python):
m,k=map(int,input().split())
if m==1 and k==0:
    a=[0,0,1,1]
    print(*a)
    exit()
elif m==1 and k==1:
    print(-1)
    exit()
if k<=2**m-1:
    ans=[]
    for i in range(2**(m)):
        if i!=k:
            ans.append(i)
    ans.append(k)
    for i in range(2**m-1,-1,-1):
        if i!=k:
            ans.append(i)
    ans.append(k)
    print(*ans)
else:
    print(-1)

Solution (Python):
M, K = map(int, input().split())
if K >= 2**M:
    print(-1)
elif M == 0:
    print(0, 0)
elif M == 1:
    if K == 0:
        print("0 0 1 1")
    else:
        print(-1)
elif K==0:
    r = list(range(2**M))
    r += r[::-1]
    print(*r)
else:
    d = set()
    for i in range(2**M):
        p = tuple(sorted([i, i^K]))
        if p not in d:
            d.add(p)
    r = []
    while d:
        x,y = d.pop()
        z,w = d.pop()
        r += [x,y,z,w,y,x,w,z]
    print(*r)

Solution (Python):
m,k = map(int, input().split())

if k>=2**m:
    print(-1)
    exit()

if m==0:
    print(0,0)
elif m==1:
    if k==0:
        print(0,0,1,1)
    else:
        print(-1)
else:
    for i in range(2**m):
        if i!=k:
            print(i,end=' ')
    print(k,end=' ')
    for i in range(2**m-1,-1,-1):
        if i!=k:
            print(i,end=' ')
    print(k)

Solution (Python):
m,k = map(int,input().split())
if k>=2**m:
    print(-1)
    exit()
if m == 1:
    if k == 0:
        print(0,0,1,1)
    else:
        print(-1)
    exit()
ans = [0 for _ in range(2**(m+1))]
for i in range(2**m):
    if i < k:
        ans[i] = i
        ans[2**(m+1)-2-i] = i
    if i == k:
        continue
    if i > k:
        ans[i-1] = i
        ans[2**(m+1)-i-1] = i
ans[2**m-1] = k
ans[2**(m+1)-1] = k
print(*ans,sep=" ")

Solution (Python):
M,K = map(int,input().split())
if [M,K] == [1,1] or K>=2**M:
    print(-1)
elif [M,K] == [1,0]:
    print('0 0 1 1')
else:
    ans = []
    for i in range(2**M):
        if i != K:
            ans.append(i)
    ans = ans+[K]+ans[::-1]+[K]
    print(*ans)

Solution (Python):
def solve(m, k):
    if k >= 2**m:
        return -1
    if (m == 1) and (k == 0):
        return "0 0 1 1"
    if (m == 1) and (k == 1):
        return -1
    b = [x for x in range(2**m) if x != k]
    c = b[::-1]
    a = b + [k] + c + [k]
    return " ".join(map(str, a))

m, k = map(int, input().split())
print(solve(m, k))

Solution (Python):


import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

"""
[解説AC]
1. k>=2**mのとき
明らかに-1
2. m=0のとき
同じ数2つなのでxorは必ず0
3. m=1のとき
k=0なら2種類の数を2つずつ並べる
k!=0なら2種類の数2つずつの並べ方はk=0の場合の並べ方以外で
2種類(交互に並べる,片方の種類の数の間にもう一方の数2枚)
交互に並べる場合,明らかにxorが異なる⇒×
片方の種類の数の間にもう一方の数2枚,明らかにxor=0になる⇒×
つまり、k!=0のとき-1
4.m>=2のとき
k以外の0以上2**m未満の数を昇順に並べる⇒bとする
k以外の0以上2**m未満の数を降順に並べる⇒cとする
bkckと並べると常にxor=kを満たす
k以外の0以上2**m未満の数の任意の数について、その間にはkが1つと
他の数が常に2つずつ入っている⇒xorは必ずk
kについて、間にはcがあるが、cはk以外の0以上2**m未満の数であり、
kが2つとc⇒0以上の2**未満の数とkのxor
0以上2**m未満の数については(2**m)-1が偶数個作れるため0であり、0xork=k
"""

m,k = LI()

if k >= 2**m:
    print(-1)
    quit()
if m == 0:
    if k == 0:
        print(0,0)
    else:
        print(-1)
elif m == 1:
    if k == 0:
        ans = [i for i in range(2**(m+1))]
        ans = [i//2 for i in ans]
        print(*ans)
    else:
        print(-1)
else:
    ans = [i for i in range(2**m) if i != k]
    ans = ans + [k] + ans[::-1] + [k]
    print(*ans)

Solution (Python):


import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))


m,k = LI()

if k >= 2**m:
    print(-1)
    quit()
if m == 0:
    if k == 0:
        print(0,0)
    else:
        print(-1)
elif m == 1:
    if k == 0:
        ans = [i for i in range(2**(m+1))]
        ans = [i//2 for i in ans]
        print(*ans)
    else:
        print(-1)
else:
    ans = [i for i in range(2**m) if i != k]
    ans = ans + [k] + ans[::-1] + [k]
    print(*ans)

Solution (Python):

M,K = map(int,input().split())

if K >= 2 ** M:
    print (-1)

elif M == 1 and K == 0:
    print ("0 0 1 1")

elif M == 1 and K == 1:
    print ("-1")

else:
    ans = []

    for i in range(2 ** M):
        if i != K:
            ans.append(i)

    ans.append(K)

    for i in range(2 ** M):
        if 2 ** M - i - 1 != K:
            ans.append(2 ** M - i - 1)

    ans.append(K)

    print (" ".join(map(str,ans)))

Solution (Python):
m,k=map(int,input().split())
if pow(2,m) <= k:
	print(-1)
	exit()

if m==0:
	if k==0:
		print(0,0)
	else:
		print(-1)
	exit()

if m==1:
	if k==0:
		print(0,0,1,1)
	else:
		print(-1)
	exit()
b=[]
c=[]
for i in range(pow(2,m)):
	if i!=k:
		b.append(i)
	if pow(2,m)-1-i!=k:
		c.append(pow(2,m)-1-i)

ans = " ".join([str(x) for x in b])
ans += " "
ans+=str(k)
ans += " "
ans += " ".join([str(x) for x in c])
ans += " "
ans+=str(k)

print(ans)

Solution (Python):
m,k = map(int, input().split())

if k == 0:
    ans = []
    for i in range(1<<m):
        ans.append(i)
        ans.append(i)
elif 1<<m <= k or m==1:
    ans = [-1]
else:
    ans = [i for i in range(1<<m) if i!=k]
    ans = ans + [k] + ans[::-1] + [k]

print(*ans)

Solution (Python):
m,k=map(int,input().split())
if k>=2**m:
    print(-1)
    exit()
if m==0:
    print(0,0)
    exit()
if m==1:
    if k==0:
        print(0,0,1,1)
    else:
        print(-1)
    exit()
ans=[]
for i in range(2**m):
    if i==k:
        continue
    ans.append(i)
ans.append(k)
for i in range(2**m-1,-1,-1):
    if i==k:
        continue
    ans.append(i)
ans.append(k)
print(*ans)

Solution (Python):
import sys
import itertools
m,k=map(int,input().split())
if k>=2**m:
    print(-1)
    sys.exit()

if m==0:
    if k==0:
        print("0 0")
    else:
        print(-1)
    sys.exit()
if m==1:
    if k==0:
        print("1 1 0 0")
    else:
        print(-1)
    sys.exit()
    
lst=[]
for i in range(m):
    if (k>>i)&1==1:
        lst.append(2**i)
    
ans_1=[]
for i in range(2**m):
    if i in lst:
        continue
    else:
        ans_1.append(i)

ans_1+=lst
ans_2=[]
for i in range(2**m-1,-1,-1):
    if i in lst:
        continue
    else:
        ans_2.append(i)
ans_2+=lst[::-1]
ans=ans_1+ans_2
print(*ans)

Solution (Python):
import sys
m,k=map(int,input().split())
if 2**m<=k:
  print(-1)
  sys.exit()
if m==1 and k==1:
  print(-1)
  sys.exit()
if m==1 and k==0:
  print('0 0 1 1')
  sys.exit()
if m==0:
  print('0 0')
  sys.exit()

l=[]
for i in range(2**m):
  if i!=k:
    l.append(str(i))
print(' '.join(l+[str(k)]+list(reversed(l))+[str(k)]))

Solution (Python):
def main():
    m,k=map(int,input().split())
    if 2**m<=k:
        print(-1)
    elif m==0:
        if k==0:
            print(0,0)
        else:
            print(-1)
    elif m==1:
        if k==0:
            print(1,0,0,1)
        else:
            print(-1)
    else:
        ans=[]
        for i in range(2**m-1,-1,-1):
            if i!=k:
                ans.append(i)
        ans.append(k)
        for i in range(2**m):
            if i!=k:
                ans.append(i)
        ans.append(k)
        print(*ans)
main()

Solution (Python):
m, k = map(int, input().split())
limit = 2 ** m

if k >= limit:
  print(-1)
  exit()

if m == 0:
  print(0, 0)
elif m == 1:
  if k == 0:
    print(0, 0, 1, 1)
  elif k == 1:
    print(-1)
else:
  A = [i for i in range(limit) if i != k]
  ans = A + [k] + A[::-1] + [k]
  print(' '.join(map(str, ans)))

Solution (Python):
from collections import deque


def p_f():
    m, k = map(int, input().split())
    length = 1 << (m + 1)
    n = 1 << m
    if n <= k:
        print(-1)
        exit()

    if m == 1 and k == 0:
        print("0 0 1 1")
        exit()
    elif m == 1 and k == 1:
        print(-1)
        exit()

    d = deque()
    d.append(k)
    for i in range(n):
        if i == k:
            continue
        d.append(i)
        d.appendleft(i)
    d.append(k)
    print(*d)


if __name__ == '__main__':
    p_f()

Solution (Python):

m,k = map(int,input().split())
if k >= 2**m:
  print(-1)
elif m == 1 and k == 1:
  print(-1)
elif m == 1 and k == 0:
  print(1,1,0,0)
else:
  a = []
  for i in range(2**m):
    if i != k:
      a.append(i)
  b = list(reversed(a))
  ans = b + [k] + a + [k]
  
  print(' '.join((list(map(str,ans)))))

Solution (Python):
M, K = map(int, input().split())
if K>(1<<M)-1:
    print(-1)
elif M == 1 and K == 1:
    print(-1)
elif M == 1 and K == 0:
    print(0, 0, 1, 1)
elif M == 0 and K == 0:
    print(0, 0)
elif M == 0:
    print(-1)
else:
    N = 1<<M
    ans = list(range(K))+list(range(K+1, N))+[K]+list(range(K+1, N))[::-1]+list(range(K))[::-1]+[K]
    print(*ans)