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):
import sys

M, K = map(int, input().split())
if K >= pow(2, M) or (M==1 and K==1):
    print(-1)
    sys.exit()
ans = []
if K == 0:
    for i in range(pow(2, M)):
        ans.append(i)
        ans.append(i)
else:
    for i in range(pow(2, M)):
        if i != K:
            ans.append(i)
    ans.append(K)
    for i in range(pow(2, M)-1, -1, -1):
        if i != K:
            ans.append(i)
    ans.append(K)
print(' '.join(map(str, ans)))

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

num = 2**(M+1)

if K >= num//2 or (M==1 and K==1):
    ans = [-1]
elif M==1 and K==0:
    ans = [0,0,1,1]
else:
    ans = [0]*num
    for i in range(2**M):
        if i==K: continue
        ans[i-(i>K)] = i
        ans[num-2-i+(i>K)] = i
    ans[num//2-1] = K
    ans[-1] = K
    
print(*ans)

Solution (Python):
def main(m,k): 
  if k==0:
    ary=[]
    for i in range(2**m):
      ary.append(i)
      ary.append(i)
    return ary
  elif k>=2**m or m==1:
    return [-1]
  else:
    mi=set(range(2**m))
    b=[]
    while mi:
      i=mi.pop()
      j=i^k
      mi.discard(j)
      u=mi.pop()
      v=u^k
      mi.discard(v)
      b.append((i,j,u,v))
    ary=[]
    for i,j,u,v in b:
      ary.append(i)
      ary.append(j)
      ary.append(u)
      ary.append(v)
      ary.append(j)
      ary.append(i)
      ary.append(v)
      ary.append(u)
    return ary

m,k=map(int,input().split())
ary=main(m,k)

print(*ary,sep=' ')
exit()
print(len(ary))

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

    max_a = pow(2, m)

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

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

    l = [0] * (2 * max_a)
    l[0] = k
    l[max_a] = k
    for i in range(k):
        l[i + 1] = i
        l[-i - 1] = i
    for i in range(k + 1, max_a):
        l[i] = i
        l[-i] = i
    print(' '.join(map(str, l)))

main()

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

    max_a = pow(2, m)

    if k >= max_a:
        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()

    l = [0] * (2 * max_a)
    l[0] = k
    l[max_a] = k
    for i in range(k):
        l[i + 1] = i
        l[-i - 1] = i
    for i in range(k + 1, max_a):
        l[i] = i
        l[-i] = i
    print(' '.join(map(str, l)))

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)
elif k==0:
  print(" ".join(map(str,[i//2 for i in range(2**(m+1))])))
else:
  l=[i+int(i>=k) for i in range(1,2**m-1)]
  ll=[i+int(i>=k) for i in range(2**m-2,0,-1)]
  ans=[k]+l+[k,0]+ll+[0]
  print(" ".join(map(str,ans)))

Solution (Python):
def GSB(n):
	ans = -1
	for i in range(30):
		if n&(1<<i):
			ans = i
	return ans
def ans(a,b,c,d,M):
	other = [x for x in range(1<<M) if x not in [a,b,c,d]]
	print(*([a,b]+other+[c,d]+other[::-1]+[b,a,d,c]))

def solve(M,K):
	if K==0:
		arr = list(range(1<<M))
		print(*(arr+arr[::-1]))
	elif K==1:
		if M < 2:
			print(-1)
		else:
			ans(0,1,2,3,M)
	else:
		if M > GSB(K):
			a = 1<<GSB(K)
			b = K^a
			c = a+1
			d = K^c
			ans(a,b,c,d,M)
		else:
			print(-1)


solve(*map(int,input().split()))

Solution (Python):
m,k=map(int,input().split())
a=['']*(2**(m+1))
if k==0:
    for i in range(2**m):
        for j in range(2):
            a[2*i+j]=str(i)
else:
    xor=0
    for i in range(2**m):
        if i<k:
            a[i]=str(i)
            xor^=i
        elif i>k:
            a[i-1]=str(i)
            xor^=i
    
    if xor!=k:
        print(-1)
        exit(0)
    
    a[2**m-1]=str(k)
    for i in range(2**m-1,-1,-1):
        if i>k:
            a[2**(m+1)-i-1]=str(i)
        elif i<k:
            a[2**(m+1)-i-2]=str(i)
    
    a[2**(m+1)-1]=str(k)


print(' '.join(a))

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

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

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

if k == 0:
    t = []
    for i in range(1 << m):
        for _ in range(2):
            t.append(i)
    print(*t)
    exit()

b = []
for i in range(1 << m):
    if i != k:
        b.append(i)

c = b[::-1]

a = b + [k] + c + [k]
print(*a)

Solution (Python):
import sys
from itertools import permutations

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    M, K = map(int, readline().split())

    if M == 0:
        if K == 0:
            print(0, 0)
            return
        else:
            print(-1)
            return
    elif M == 1:
        if K == 0:
            print(0, 0, 1, 1)
            return
        else:
            print(-1)
            return
    elif K >= pow(2, M):
        print(-1)
        return

    vec = [i for i in range(pow(2, M)) if i != K]
    ans = vec + [K] + vec[::-1] + [K]

    print(' '.join(map(str, ans)))
    return


if __name__ == '__main__':
    main()

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache





MOD = 10**9+7
INF = float('inf')
AZ = "abcdefghijklmnopqrstuvwxyz"






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()


def DD(arg): return defaultdict(arg)


def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n): return kaijo_memo[n]
  if(len(kaijo_memo) == 0): kaijo_memo.append(1)
  while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if n == r: return 1
  if n < r or r < 0: return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1: arr.append([temp, 1])
  if arr==[]: arr.append([n, 1])
  return arr


def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors


def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum


def gcd(a, b):
    while b: a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd (a, b)


def count_bit(n):
  count = 0
  while n:
    n &= n-1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n: return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

def base_10_to_n_without_0(X, n):
  X -= 1
  if X//n: return base_10_to_n_without_0(X//n, n)+[X%n]
  return [X%n]


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count




M,K = IL()
MM = 1<<M

if K>=MM:
  print(-1)
  exit()
else:
  if M==1:
    if K==1:
      print(-1)
    else:
      print(0,0,1,1)
  else:
    print(*list([K]+list(range(K))+list(range(K+1,MM))+[K]+list(range(K+1,MM)[::-1])+list(range(K)[::-1])),sep=" ")

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

if 2**M-1<K:
    print(-1)
    exit()
if M==1:
    if K==0:
        print(0,0,1,1)
    if K==1:
        print(-1)
    exit()

res=0
li=[]
for i in range(2**M):
    if i==K:
        continue
    li.append(i)
ans=[K]+li+[K]+li[::-1]
print(*ans)

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

if 2**M-1<K:
    print(-1)
    exit()
if M==1 and K==0:
    print(0,0,1,1)
    exit()

res=0
li=[]
for i in range(2**M):
    if i==K:
        continue
    res=res^i
    li.append(i)
if res!=K:
    print(-1)
    exit()

ans=[K]+li+[K]+li[::-1]
print(*ans)

Solution (Python):
M, K = map(int, input().split())
A = iter(range(2**19))
S = set()
D = []
if K==0:
    for i in range(2**M):
        D += [i, i]
    print(*D)
    exit()
while True:
    while True:
        a = next(A)
        if K^a not in S: break
    S |= {a}
    while True:
        b = next(A)
        if K^b not in S: break
    S |= {b}
    if b >= 2**M or K^b >= 2**M or K^a >= 2**M:
        print(-1)
        exit()
    D += [a, K^a, b, K^b, K^a, a, K^b, b]
    if len(D)==2**(M+1):
        break
print(*D)

Solution (Python):





import sys

m, k = map(int, input().strip().split())
max_num = 2**m
if k >= max_num:
    print(-1)
    sys.exit()

if m == 0:
    print('0 0')
    sys.exit()

if m == 1:
    if k == 0:
        print('0 0 1 1')
    else:
        print('-1')
    sys.exit()

res = []
for i in range(max_num):
    if i == k:
        continue
    res.append(i)
res.append(k)
for i in range(max_num):
    j = max_num - i - 1
    if j == k:
        continue
    res.append(j)
res.append(k)
for i in range(2**(m+1)):
    print(res[i], end=' ')

Solution (Python):





import sys

m, k = map(int, input().strip().split())
max_num = 2**m
if k >= max_num:
    print(-1)
    sys.exit()





if m == 1:
    if k == 0:
        print('0 0 1 1')
    else:
        print('-1')
    sys.exit()

res = []
for i in range(max_num):
    if i == k:
        continue
    res.append(i)
res.append(k)
for i in range(max_num):
    j = max_num - i - 1
    if j == k:
        continue
    res.append(j)
res.append(k)
for i in range(2**(m+1)):
    print(res[i], end=' ')

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

if K == 0:
    print(*(list(range(2 ** M)) + list(range(2 ** M - 1, -1, -1))))
else:
    if M <= 1:
        print(-1)
    elif K.bit_length() > M:
        print(-1)
    else:
        index = 0
        used = [False] * (2 ** M)
        ans = []
        for _ in range(2 ** (M-2)):
            while index < 2 ** M and used[index]:
                index += 1
            A = index
            C = index ^ K
            used[index] = True
            used[index^K] = True
            while index < 2 ** M and used[index]:
                index += 1
            B = index
            D = index ^ K
            used[index] = True
            used[index^K] = True
            ans += [A, C, B, D, C, A, D, B]
        print(*ans)

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

if K >= 2 ** M:
    print(-1)
elif (M, K) == (1, 0):
    print(*(0, 0, 1, 1))
elif (M, K) == (1, 1):
    print(-1)
else:
    
    ans = [0] * (2 ** (M + 1))
    ans[2 ** M - 1] = ans[-1] = K

    num = 0
    for i in range(2 ** M - 1):
        if num == K:
            num += 1
        ans[2 ** M - i - 2] = ans[2 ** M + i] = num
        num += 1
    print(*ans)

Solution (Python):
m,k=map(int,input().split())
if k>=2**m:
  print(-1)
  exit()
if m==1 and k==1:
  print(-1)
  exit()
if k==0:
  ans=[]
  for i in range(2**m):
    ans.append(i)
    ans.append(i)
else:
  ans=[k]
  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)
print(*ans,sep=' ')

Solution (Python):
import sys

input = sys.stdin.readline



def main():
    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()

    A = list(range(2 ** M))
    B = list(reversed(range(2 ** M)))
    A.remove(K)
    B.remove(K)

    ans = A + [K] + B + [K]
    print(" ".join(map(str, ans)))


if __name__ == "__main__":
    main()

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    M,K=MI()
    N=pow(2,M)
    if K>=N:
        print(-1)
        exit()
    elif M==1 and K==0:
        print(0,0,1,1)
    else:
        ans=[]
        temp=0
        for i in range(N):
            if i!=K:
                ans.append(i)
                temp=temp^i
        ans.append(K)
        for i in range(N-1,-1,-1):
            if i!=K:
                ans.append(i)
        ans.append(K)
        if temp!=K:
            print(-1)
        else:
            print(' '.join(map(str, ans)))        

                

main()

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, 1, 1, 0)
    else:
        print(-1)
else:
    a = 2 ** m - 1
    if k > a:
        print(-1)
    else:
        for num in range(a + 1):
            if num == k:
                continue
            print(num, end = " ")
        print(k, end = " ")
        for num in range(a, -1, -1):
            if num == k:
                continue
            print(num, end = " ")
        print(k)

Solution (Python):

def main():
    M, K = map(int, input().split())
    if K == 0:
        print(*[i//2 for i in range(2**(M+1))])
    else:
        if K >= 2**M or M <= 1:
            print(-1)
        else:
            nums = []
            for i in range(2**M):
                if i != K:
                    nums.append(i)
            a = [nums[0], K, nums[0]]
            b = []
            for i in range(1,2**M-1):
                b.append(nums[i])
            b.append(K)
            for i in range(1,2**M-1):
                b.append(nums[2**M-1-i])
            print(*a,*b)
if __name__ == "__main__":
    main()

Solution (Python):
M,K = map(int,input().split())
if K>=2**M:
    print(-1)
else:
    if M==1:
        if K==1:
            print(-1)
        elif K==0:
            print("1 0 0 1")
    else:
        A = []
        for i in range(2**M-1,-1,-1):
            if i==K:continue
            A.append(i)
        A.append(K)
        for i in range(2**M):
            if i==K:continue
            A.append(i)
        A.append(K)
        print(*A)

Solution (Python):
m, k = map(int, input().split())
if m==1 and k==0:
    print(0,0,1,1)
    exit()
if m==k==1:
    print(-1)
    exit()

if 2**m<=k:
    print(-1)
    exit()
ans = [k]
for i in range(2**m):
    if i != k:
        ans.append(i)
ans.append(k)
for i in reversed(range(2**m)):
    if i != k:
        ans.append(i)
print(*ans)

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

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

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

l = [i for i in range(2**M) if i!=K]
print(*(list(reversed(l))+[K]+l+[K]))

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

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:
  for i in range(2**m):
    if i == k:
      continue
    print(i, end=" ")
  print(k, end=" ")
  for i in range(2**m-1, -1, -1):
    if i == k:
      continue
    print(i, end=" ")
  print(k)

Solution (Python):
'''
研究室PCでの解答
'''
import math

import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit


ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7
dir = [(-1,0),(1,0),(0,-1),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"


def main():
    m,k = map(int,ipt().split())
    if m == 1:
        if k == 0:
            print("0 1 1 0")
        else:
            print(-1)
        exit()
    if k <= 2**m-1:
        a = []
        b = []
        for i in range(m):
            if (k>>i)&1:
                a.append(2**i)
        sa = set(a)
        for i in range(2**m):
            if not i in sa:
                b.append(i)
        print(" ".join(map(str,a+b+a[::-1]+b[::-1])))
    else:
        print(-1)

    return None

if __name__ == '__main__':
    main()

Solution (Python):
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7

INF = 10**18
eps = 10**-7

m,k = map(int,readline().split())

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

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

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

ans = []

for i in range(2**m):
    if i != k:
        ans.append(i)
anss = [k] + ans + [k] + ans[::-1]
print(" ".join(map(str,anss)))

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7










M, K = getNM()

if M == 0 and K == 0:
    print(0, 0)

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

elif M >= 2 and K < 2 ** M:
    ans = []
    for n in range(2 ** M):
        if n != K:
            ans.append(n)
    print(*ans, K, *ans[::-1], K)
    
else:
    print(-1)

Solution (Python):
m,k=map(int,input().split())
if 2**m<=k or m*k==1:
    print(-1)
elif m==1 and k==0:
    print("0 0 1 1")
else:
    ans=[-1 for i in range(2**(m+1))]
    sta=2**m-1
    cnt=0
    for i in range(1,2**m):
        if cnt==k:
            cnt+=1
        ans[sta+i]=cnt
        ans[sta-i]=cnt
        cnt+=1
    ans[sta]=k
    ans[-1]=k
    
    print(" ".join([str(i) for i in ans]))

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



if K >= 2 ** M:
  print("-1")
  quit()
if M == 0:
  print(0, 0)
  quit()
elif M == 1:
  if K == 0:
    print(0, 0, 1, 1)
  else:
    print(-1)
  quit()

  
now = 0  
for i in range(2 ** M):
  if i != K:
    now = now^i
  


print(K, end = " ")
for i in range(2 ** M):
  if i != K:
    print(i, end = " ")
print(K, end = " ")
for i in range(2 ** M):
  if (2 ** M - 1 - i) != K:
    print(2 ** M - 1 - i, end = " ")

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

if K >= 2**M:
    print(-1)
    exit()
elif M == 0:
    print("0 0")
elif M == 1:
    if K == 0:
        print("0 0 1 1")
    else:
        print(-1)
else:
    A = [i for i in range(2**M) if i != K]
    B = A[::-1]

    for a in A: print(a, end = " ")
    print(K, end=" ")
    for b in B: print(b, end=" ")
    print(K)

Solution (Python):

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

if M == 0 and K == 0:
    print(0, 0)
elif M == 1 and K == 0:
    print(0, 0, 1, 1)
elif M >= 2 and K < 2 ** M:
    tmp = []
    for n in range(2 ** M):
        if n != K:
            tmp.append(n)
    print(*tmp, K, *tmp[::-1], K)
else:
    print(-1)

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

Solution (Python):
M,K=map(int,input().split())
if (1<<M)<=K or (K==1 and M==1):
  print(-1)
  exit()
if M==1:
  print('0 0 1 1')
  exit()
X=[]
for i in range(1<<M):
  if i!=K:
    X.append(i)
X.append(K)
for i in range((1<<M)-1,-1,-1):
  if i!=K:
    X.append(i)
X.append(K)
print(*X)

Solution (Python):
import sys
input = sys.stdin.readline
from functools import reduce
from operator import xor


def read():
    M, K = map(int, input().strip().split())
    return M, K


def solve(M, K):
    seq = [str(0) for i in range(2**(M+1))]
    if K == 0:
        for i in range(2**M):
            seq[2*i] = str(i)
            seq[2*i+1] = str(i)
    else:
        if K >= 2**M:
            return -1
        
        S = [a for a in range(2**M) if a not in (0, K)]
        if len(S) == 0 or reduce(xor, S) != K:
            return -1
            
        j = 0
        for i in range(2**M-2):
            j += 1
            if j == K:
                j += 1
            seq[i+1] = str(j)
            seq[2**(M+1) - i - 1] = str(j)
        seq[0] = str(K)
        seq[2**M] = str(K)
        
    return " ".join(seq)


if __name__ == '__main__':
    inputs = read()
    print(solve(*inputs))

Solution (Python):
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())

M,K = MI()

if K >= 2**M or (M == 1 and K == 1):
    print(-1)
elif M == 1 and K == 0:
    print(*[0,0,1,1])
else:
    A = [i for i in range(2**M) if i != K]
    ANS = A + [K] + list(reversed(A)) + [K]
    print(*ANS)

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

if k > 2 ** m - 1 or m == 1 and k == 1:
    print(-1)
    quit()

if k == 0:
    print(' '.join(map(lambda x : str(x // 2), range(0, 2 ** (m + 1)))))
    quit()

a = list(range(0, 2 ** m)) 
a.remove(k)
ans = a + [k]
a.reverse()
ans += a + [k]
print(' '.join(map(str, ans)))

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




def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))


from collections import deque

def main():
	m,k=MI()
	A=[]
	if k==0:
		for i in range(2**m):
			A.append(i)
			A.append(i)
		print(*A)
		exit()

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

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

	A.append(0)
	A.append(k)
	A.append(0)

	for i in range(1,2**m):
		if i!=k:
			A.append(i)
	A.append(k)

	for i in reversed(range(1,2**m)):
		if i!=k:
			A.append(i)

	print(*A)


















if __name__ == "__main__":
	main()

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

Solution (Python):
import sys
from collections import defaultdict, deque, Counter
import math
 

from bisect import bisect_left, bisect_right

 

 

input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]
 
INF = 10 ** 20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)
 


def main():
    m, k = getList()
    if k == 0:
        ans = []
        for i in range(2**m):
           
            ans.append(i)
        
        for i in range(2**m-1, -1, -1):
            
            ans.append(i)

   
        print(*ans)
        return 
    if m <= 1 and k != 0:
        print(-1)
        return 
    if 2 ** m <= k:
        print(-1)
        return 
    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)

if __name__ == "__main__":
    main()

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

if 2 ** M <= K:
  print(-1)
  exit(0)
  
if M == 0:
  print(0,0)
elif M == 1 and K == 0:
  print(0,0,1,1)
elif M == 1 and K >= 1:
  print(-1)
else:
  A = list(range(2**M))
  B = A[:K] + A[K+1:]
  C = map(str, B + [K] + B[::-1] + [K])
  print(" ".join(C))

Solution (Python):




import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial,sqrt
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

m,k=MI()
if m==1 and k==1:
    print(-1)
    sys.exit()
if m==1 and k==0:
    lis=[0,0,1,1]
    print(*lis)
    sys.exit()
if k>=2**m:
    print(-1)
    sys.exit()
else:
    pre_lis=[]
    for i in range(2**m):
        if i==k:
            continue
        pre_lis.append(i)
    
    ans=[0 for i in range(2**(m+1))]
    ans[0]=k
    for i in range(len(pre_lis)):
        ans[i+1]=pre_lis[i]
        ans[2**(m+1)-i-1]=pre_lis[i]
    ans[len(pre_lis)+1]=k
print(*ans)

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

if (m == 1 and k == 1) or (2 ** m <= k):
    print(-1)
    sys.exit()

if m == 1 and k == 0:
    print('1 1 0 0')
    sys.exit()

if m == 0 and k == 0:
    print('0 0')
    sys.exit()

f = 1
p = 0
p2 = []

for i in range(2 ** m):
    if i == k:
        continue
    else:
        if f:
            p = i
            f = 0
        else:
            p2.append(i)

ans = [p, k, p] + p2 + [k] + list(reversed(p2))
print(' '.join(list(map(str, ans))))

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()

N = 2 ** M
if N <= K:
	print(-1)
	exit()

ans = []
ans.append(K)

for i in range(N):
	if i == K:
		continue
	ans.append(i)

ans.append(K)

for i in range(N-1, -1, -1):
	if i == K:
		continue
	ans.append(i)

for i in ans:
	print(i, end=' ')

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

Solution (Python):
import sys

stdin = sys.stdin


def ni(): return int(ns())


def na(): return list(map(int, stdin.readline().split()))


def naa(N): return [na() for _ in range(N)]


def ns(): return stdin.readline().rstrip()  


M, K = na()
if 2 ** M <= K:
    print(-1)
    exit()
if M == 1:
    if K == 0:
        print("0 0 1 1")
        exit()
    else:
        print(-1)
        exit()
ans_array = [0] * (2 ** (M+1))

for i in range(2**M-1):
    ans_array[i] = i if i < K else i + 1

ans_array[2**M-1] = K

for i in range(2**M-1, 0, -1):
    ans_array[-(i+1)] = i if i > K else i - 1

ans_array[-1] = K
print(" ".join(map(str, ans_array)))

Solution (Python):
m,k=map(int,input().split())
x=[*range(1<<m)]
print(*(([-1],[k]+x[k+1:]+x[:k]+[k]+x[k-1::-1]+x[:k:-1])[k<1<<m>2],x+x[::-1])[k<1])

Solution (Python):
m,k=map(int,input().split())
x=[*range(1<<m)]
print(*k<1and x+x[::-1]or k<1<<m>2and[k]+x[k+1:]+x[:k]+[k]+x[k-1::-1]+x[:k:-1]or[-1])

Solution (Python):
m,k=map(int,input().split())
x=[*range(1<<m)]
print(*(x+x[::-1])*(k<1)or([k]+x[k+1:]+x[:k]+[k]+x[k-1::-1]+x[:k:-1])*(k<1<<m>2)or[-1])

Solution (Python):
m,k=map(int,input().split())
x=[*range(1<<m)]
print(*(x+x[::-1])*(k<1)or([k]+x[k+1:]+x[:k]+[k]+x[k-1::-1]+x[:k:-1])*(m>1<=k<1<<m)or[-1])

Solution (Python):
m,k=map(int,input().split())
x=[*range(1<<m)]
print(*(x+x[::-1])*(k<1)or([k]+x[k+1:]+x[:k]+[k]+x[k-1::-1]+x[:k:-1])*(k<2**m)*(m>1)or[-1])

Solution (Python):
m,k=map(int,input().split())
x=[*range(1<<m)]
print(*x+x[::-1]if k<1else[k]+x[k+1:]+x[:k]+[k]+x[k-1::-1]+x[:k:-1]if(k<2**m)&(m>1)else[-1])

Solution (Python):
m,k=map(int,input().split())
x=[*range(1<<m)]
print(*x+x[::-1]if k<1else x[:k:-1]+x[k-1::-1]+[k]+x[:k]+x[k+1:]+[k]if(k<2**m)&(m>1)else[-1])

Solution (Python):
m,k=map(int,input().split())
x=[*range(1<<m)]
print(*x[::-1]+x if k<1else x[:k:-1]+x[k-1::-1]+[k]+x[:k]+x[k+1:]+[k]if(k<2**m)&(m>1)else[-1])

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

if K >= pow(2, M):
    print(-1)
elif K == 0:
    ans = []
    for i in range(pow(2, M)):
        ans.append(i)
        ans.append(i)
    print(*ans)
else:
    num = 0
    L = []
    for i in range(pow(2, M)):
        if i == K:
            continue
        num ^= i
        L.append(i)
    if num == K:
        L2 = list(reversed(L))
        ans = L + [K] + L2 + [K]
        print(*ans)
    else:
        print(-1)

Solution (Python):

import sys
INF = float("inf")


def main():
    M, K = map(int, input().split())

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

    
    if K >= (1 << M):
        print("-1")
        return

    
    ans = []
    for i in range(1 << M):
        if i == K:
            continue
        ans.append(i)
    ans = ans[::-1] + [K] + ans + [K]
    print(" ".join(map(str, ans)))


if __name__ == '__main__':
    main()