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,os,math
from collections import Counter, defaultdict, deque
import bisect
from sys import stdin, stdout
from itertools import repeat
import Queue
import time
 
 




 
BT = int(1e9)
def main():
    start = time.time()
    m, k = map(int, raw_input().split())
    if k >= (1<<m):
        print -1
        return
    if m==1 and k==0:
        print 1,1,0,0
        return
    if m==1 and k==1:
        print -1
        return
    ans = []
    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)    
    ans.append(k)
    print ' '.join(map(str, ans))

 
main()

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

if K == 0:
    ans = list(range(1 << M)[:: -1]) + list(range(1 << M))
    print(*ans)
    exit()

A = []
B = []

used = [False] * (1 << M)
for d in range(M):
    if ((1 << d) & K) != 0:
        A.append(1 << d)
        used[1 << d] = True

for i in range(1 << M):
    if used[i]:
        continue
    else:
        B.append(i)

xorA = 0
for a in A:
    xorA ^= a

xorB = 0
for b in B:
    xorB ^= b

if xorA != K or xorB != K:
    print(-1)
    exit()

A.sort()
B.sort()
ans = A + B + A[:: -1] + B[:: -1]
print(*ans)

Solution (Python):
def examF():
    M, K = LI()
    if K>=(2**M) or (M==1 and K==1):
        ans = -1
    elif K==0:
        ans = []
        s = [i for i in range(2**M)]
        for i in range(2**M):
            ans.append(i)
            ans.append(i)
    else:
        ans = []
        ans.append(K)
        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)
    if type(ans) is int:
        print(ans)
    else:
        print(" ".join(map(str,ans)))

import sys
import copy
import bisect
import heapq
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examF()

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

if K == 0:
    for i in range(pow(2, M + 1)//2):
        print (i, i, end = '')
        if i != pow(2, M + 1)//2 - 1:
            print (' ', end = '')
    exit()

tmp = 0
for i in range(pow(2, M)):
    tmp ^= i

if K >= pow(2, M):
    print (-1)
    exit()

if tmp ^ K != K:
    print (-1)
    exit()
    

print (K, end = ' ')
for i in range(pow(2, M) - 1, -1, -1):
    if i != K:
        print (i, end = ' ')
print (K, end = ' ')
for i in range(pow(2, M)):
    if i != K:
        print (i, end = '')
        if K == pow(2, M) - 1:
            if i != pow(2, M) - 2:
                print (end = ' ')
        else:
            if i != pow(2, M) - 1:
                print (end = ' ')

Solution (Python):
m,n = map(int, input().split())
if n >= 1<<m:
  print(-1)
   
else:
  if m == 1:
    if n == 1:
      print(-1)
    else:
      print(0,0,1,1)
  else:
    ans = [i for i in range((1<<m)-1, -1, -1)]
    ans.remove(n)
    ans.append(n)
    for i in range(1<<m):
      if i == n:
        continue
      else:
        ans.append(i)
    ans.append(n)
    print(" ".join(map(str, ans)))

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    m,k=map(int,input().split())
    if(m==1):
        if(k>=1):
            print(-1)
            return
        else:
            print(0,0,1,1)
            return
    elif(k>=2**m):
        print(-1)
        return
    n=2**m
    ans=[]
    ans+=list(range(k-1,-1,-1))
    ans.append(k)
    ans+=list(range(k))
    ans+=list(range(k+1,n))
    ans.append(k)
    ans+=list(range(n-1,k,-1))
    print(*ans)
resolve()

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

if K >= 2 ** M:
    print(-1)
elif M == 1:
    print("1 0 0 1" if K == 0 else -1)
else:
    A = [str(i) for i in range(2 ** M) if i != K]
    print(" ".join(A), K, " ".join(reversed(A)), K)

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

if K >= 2 ** M:
    print(-1)
elif M == 0:
    print("0 0" if K == 0 else -1)
elif M == 1:
    print("1 0 0 1" if K == 0 else -1)
else:
    A = [str(i) for i in range(2 ** M) if i != K]
    print(" ".join(A), K, " ".join(reversed(A)), K)

Solution (Python):
M, K = map(int,input().split())
if 2**M <= K or (M==1 and K==1):
    print(-1)
    exit()
elif K == 0:
    ls = [str(i//2) for i in range(2**(M+1))]
    print(" ".join(ls))
    exit()
ls = [str(i) for i in range(2**M)]
ls2 = [str(2**M-i-1) for i in range(2**M)]
ls.remove(str(K))
ls2.remove(str(K))
ls.append(str(K))
for elem in ls2:
    ls.append(elem)
ls.append(str(K))
print(" ".join(ls))

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 >= 2**M:
    print(-1)
else:
    A = []
    for i in range(2**M):
        if i == K:
            continue
        A.append(i)
    ans = A[:] + [K] + A[::-1] + [K]
    print(' '.join([str(a) for a in ans]))

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

Solution (Python):

import functools
import operator

def solve(m, k):
    if k >= 2 ** m:
        return [-1]
    if m == 1 and k == 0:
        return [0, 1, 1, 0]
    b = list(range(2 ** m))
    b.remove(k)
    if functools.reduce(operator.xor, b, 0) != k:
        return [-1]
    a = b + [k] + list(reversed(b)) + [k]
    return a

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

Solution (Python):

import sys
input = sys.stdin.buffer.readline


from collections import defaultdict
import copy


def getlist():
	return list(map(int, input().split()))


def main():
	M, K = getlist()
	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 >= 2 ** M:
			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 - 1 - i != K:
					ans.append(2 ** M - 1 - i)
			ans.append(K)
			print(" ".join(list(map(str, ans))))

if __name__ == '__main__':
	main()

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

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

if M == 1:
    if K == 0:
        print(0,0,1,1)
    else:
        print(-1)
else:
    if K >= (1<<M):
        print(-1)
    else:
        other = list(range(1<<M)); other.remove(K)
        arr = other + [K] + other[::-1] + [K]
        print(' '.join(map(str,arr)))

Solution (Python):
import sys
def input():
	return sys.stdin.readline().strip()

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

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


def list_print(A):
	length = len(A)
	for i in range(length - 1):
		print(A[i], end="")
		print(" ", end="")
	print(A[- 1])

if M == 1:
	if K == 0:
		list_print([0, 0, 1, 1])
		exit()
	elif K == 1:
		print(-1)
		exit()


ans = [K]

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)



list_print(ans)

Solution (Python):
import sys
m,k = map(int, input().split( ))
if k>=2**m:
    print(-1)
    sys.exit()
if m==1:
    if k ==0:
        print(0,0,1,1)
    else:
        print(-1)
    sys.exit()
if m==0:
    print(0,0)
    sys.exit()
    
    
for i in range(2**m-1,-1,-1):
    if i!=k:
        print(i,end = " ")
print(k, end = " ")
for i in range(2**m):
    if i!=k:
        print(i, end = " ")
print(k)

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:
  print(K)
  for i in range(K):
    print(i)
  for i in range(K+1,2**M):
    print(i)
  print(K)
  for i in range(2**M-1,K,-1):
    print(i)
  for i in range(K-1,-1,-1):
    print(i)

Solution (Python):
m,k =map(int,input().split())
if k>=2**m:
  print(-1)
elif [m,k]==[0,0]:
  print("0 0")
elif [m,k]==[1,0]:
  print("0 0 1 1")
elif [m,k]==[1,1]:
  print(-1)
else:
  l=[]
  for iii in range(2**m):
    if iii!=k:
      l.append(iii)
  out=" ".join(map(str,l[::-1]+[k]+l+[k]))
  print(out)

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

if 2**m <= k :
  print(-1)
  exit()
if (m==1 and k !=0) :
  print(-1)
  exit()
if (m==1 and k==0) :
  print('0 0 1 1')
  exit()

ret = [k]
for i in range(2**m):
  if i!=k:
    ret.append(i)
ret.append(k)
for i in reversed(range(2**m)):
  if i!=k:
    ret.append(i)
print(' '.join(map(str,ret)))

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

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

if (M, K) == (1, 0):
    print("0 0 1 1")
elif K > (2 ** M) - 1 or (M, K) == (1, 1):
    print(-1)
else:
    elems = list(x for x in range(2 ** M) if x != K)
    print(' '.join(str(x) for x in elems), K, ' '.join(str(x) for x in reversed(elems)), K)

Solution (Python):

import sys


def solve(M: int, K: int):
    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 >= 2 ** M:
            print(-1)
        else:
            ans = [i for i in range(2 ** M) if i != K]
            ans = ans + [K] + ans[::-1] + [K]
            print(*ans)
    return




def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    M = int(next(tokens))  
    K = int(next(tokens))  
    solve(M, K)


if __name__ == '__main__':
    main()

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

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

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

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


A = [i for i in range(1 << M) if i != K]
print(*(A + [K] + A[::-1] + [K]))

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    M, K = map(int, input().split())
    answer = []
    if M==K==1:
        print(-1)
    elif 2**M - 1 < K:
        print(-1)
    elif K == 0:
        for i in range(2**M):
            answer += [i,i]
    else:
        for i in range(K):
            answer += [i]
        for i in range(K+1,2**M):
            answer += [i]
        answer += [K]
        for i in range(1,2**M-K):
            j = 2**M - i
            answer += [j]
        for i in range(2**M-K+1,2**M+1):
            j = 2**M - i
            answer += [j]
        answer += [K]
    print(*answer)
    
    
main()

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:
  print(" ".join(map(str, [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])))

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

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

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

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

Solution (Python):
def main():

    """ convenient functions
    
    
    
    
    
    """

    """convenient decorator
    
    
        
        
        
        
        
        
        
        
        
        
    """
    
    
    import sys
    sys.setrecursionlimit(10**7)
    from itertools import accumulate, combinations, permutations, product 
    
    from math import factorial, ceil, floor, sqrt
    def factorize(n):
        """return the factors of the Arg and count of each factor
        
        Args:
            n (long): number to be resolved into factors
        
        Returns:
            list of tuples: factorize(220) returns [(2, 2), (5, 1), (11, 1)]
        """
        fct = []  
        b, e = 2, 0  
        while b * b <= n:
            while n % b == 0:
                n = n // b
                e = e + 1
            if e > 0:
                fct.append((b, e))
            b, e = b + 1, 0
        if n > 1:
            fct.append((n, 1))
        return fct
    def combinations_count(n, r):
        """Return the number of selecting r pieces of items from n kinds of items.
        
        Args:
            n (long): number
            r (long): number
        
        Raises:
            Exception: not defined when n or r is negative
        
        Returns:
            long: number
        """
        
        if n < 0 or r < 0:
            raise Exception('combinations_count(n, r) not defined when n or r is negative')
        if n - r < r: r = n - r
        if r < 0: return 0
        if r == 0: return 1
        if r == 1: return n
        numerator = [n - r + k + 1 for k in range(r)]
        denominator = [k + 1 for k in range(r)]
        for p in range(2,r+1):
            pivot = denominator[p - 1]
            if pivot > 1:
                offset = (n - r) % p
                for k in range(p-1,r,p):
                    numerator[k - offset] /= pivot
                    denominator[k] /= pivot
        result = 1
        for k in range(r):
            if numerator[k] > 1:
                result *= int(numerator[k])
        return result
    def combinations_with_replacement_count(n, r):
        """Return the number of selecting r pieces of items from n kinds of items allowing individual elements to be repeated more than once.
        
        Args:
            n (long): number
            r (long): number
        
        Raises:
            Exception: not defined when n or r is negative
        
        Returns:
            long: number
        """
        if n < 0 or r < 0:
            raise Exception('combinations_with_replacement_count(n, r) not defined when n or r is negative')
        elif n == 0:
            return 1
        else:
            return combinations_count(n + r - 1, r)
    from bisect import bisect_left, bisect_right
    from collections import deque, Counter, defaultdict 
    from heapq import heapify, heappop, heappush, heappushpop, heapreplace,nlargest,nsmallest 
    from copy import deepcopy, copy 
    import operator
    from operator import itemgetter
    
    
    from functools import reduce, lru_cache
    def chmin(x, y):
        """change minimum
        if x > y, x = y and return (x, True).
        convenient when solving problems of dp[i]
        
        Args:
            x (long): current minimum value
            y (long): potential minimum value
        
        Returns:
            (x, bool): (x, True) when updated, else (x, False)
        """
        if x > y:
            x = y
            return (x, True)
        else:
            return (x, False)
    def chmax(x, y):
        """change maximum
        if x < y, x = y and return (x, True).
        convenient when solving problems of dp[i]
        
        Args:
            x (long): current maximum value
            y (long): potential maximum value
        
        Returns:
            (x, bool): (x, True) when updated, else (x, False)
        """
        if x < y:
            x = y
            return (x, True)
        else:
            return (x, False)

    from fractions import gcd 
    def gcds(numbers):
        return reduce(gcd, numbers)
    def lcm(x, y):
        return (x * y) // gcd(x, y)
    def lcms(numbers):
        return reduce(lcm, numbers, 1)

    
    
    INF = 10 ** 18
    MOD = 10 ** 9 + 7
    modpow = lambda a, n, p = MOD: pow(a, n, p) 
    def modinv(a, p = MOD):
        
        
        return modpow(a, p-2, p)
    def modinv_list(n, p = MOD):
        if n <= 1:
            return [0,1][:n+1]
        else:
            inv_t = [0,1]
            for i in range(2, n+1):
                inv_t += [inv_t[p % i] * (p - int(p / i)) % p]
            return inv_t
    def modfactorial_list(n, p = MOD):
        if n == 0:
            return [1]
        else:
            l = [0] * (n+1)
            tmp = 1
            for i in range(1, n+1):
                tmp = tmp * i % p
                l[i] = tmp
            return l
    def modcomb(n, k, fac_list = [], p = MOD):
        
        
        from math import factorial
        if n < 0 or k < 0 or n < k: return 0
        if n == 0 or k == 0: return 1
        if len(fac_list) <= n:
            a = factorial(n) % p
            b = factorial(k) % p
            c = factorial(n-k) % p
        else:
            a = fac_list[n]
            b = fac_list[k]
            c = fac_list[n-k]
        return (a * modpow(b, p-2, p) * modpow(c, p-2, p)) % p
    def modadd(a, b, p = MOD):
        return (a + b) % MOD
    def modsub(a, b, p = MOD):
        return (a - b) % p
    def modmul(a, b, p = MOD):
        return ((a % p) * (b % p)) % p
    def moddiv(a, b, p = MOD):
        return modmul(a, modpow(b, p-2, p))

    class UnionFindTree:
        """union find tree class
        TODO: fix this description...
        how to use (example):
        >>  uf = UnionFindTree(N) 
        >>  if uf.find_root(a) == uf.find_root(b):
        >>      do something
        >>  else:
        >>      do something
        >>      uf.unite(a, b)
        """
        def __init__(self, N):
            self.root = [-1] * (N+1)
            self.rank   = [0]  * (N+1)
            self.connected_num = [1] * (N+1)
    
        def find_root(self,x):
            root = self.root
            while root[x] != -1:
                x = root[x]
            return x
    
        def unite(self,x,y):
            root = self.root
            rank = self.rank
            connected_num = self.connected_num
            find_root = self.find_root
    
            rx = find_root(x)
            ry = find_root(y)
            if rx != ry:
                if rank[rx] < rank[ry]:
                    root[rx] = ry
                    rx,ry = ry,rx
                else:
                    if rank[rx] == rank[ry]:
                        rank[rx] += 1
                    root[ry] = rx       
                connected_num[rx] += connected_num[ry]

    """ initialize variables and set inputs
    
        
        
    
        
        
        
        
        
    
        
        
        
        
    
        
        
    """

    
    r = lambda: sys.stdin.readline().strip()
    r_int = lambda: int(r())
    R = lambda: list(map(int, r().split()))
    Rmap = lambda: map(int, r().split())
    Rfloat = lambda: list(map(float, r().split()))
    Rtuple = lambda: tuple(map(int, r().split()))

    """ how to treat input
    
    
    
    
    
    
    
    """

    if __name__ != '__main__':
        
        sys.stdin = open('sample.txt')

    
    

    M, K = R()
    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 2**M <= K:
        print(-1)
    else:
        ans = [0] * (2**(M+1))
        S = {i for i in range(2**M)}
        if K == 0:
            ans[0] = 0
            ans[1] = 0
            for i in range(1, 2**M):
                ans[1+i] = i
                ans[2**(M+1)-i] = i
            print(*ans)
        elif K == 2**M - 1:
            ans[0] = 0
            ans[1] = K
            ans[2] = 0
            for i in range(1, 2**M-1):
                ans[2+i] = i
                ans[2**(M+1)-i] = i
            ans[K+2] = K
            print(*ans)
        else:
            for i in range(K):
                ans[i] = i
                ans[2*K-i] = i
            ans[K] = K
            ans[-(2**M-K)] = K
            for index, i in enumerate(range(K+1,2**M)):
                ans[2*K+1+index] = i
                ans[2**(M+1)-index-1] = i
            print(*ans)
    
    
    

    """memo: how to use defaultdict of list
    
    Dic = defaultdict(list)
    
    Dic[x].append(y)
    
    for k, v in Dic.items():
    """

if __name__ == '__main__':
    main()

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

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

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

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=" ")
print(K)

Solution (Python):


import sys


s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    M, K = i2nn()
    
    if K == 0:
        for i in range(2**M):
            print(i, end=' ')
            print(i, end=' ')
        print()
        return
    
    if K >= 2**M:
        print(-1)
        return

    B = [i for i in range(0, 2**M) if i != K]
    C = [i for i in range(0, 2**M) if i != K]
    C.reverse()
    
    
    
    
    n = 0
    for c in C:
        n ^= c
    if n != K:
        print(-1)
        return
    
    for b in B:
        print(b, end=' ')
    print(K, end=' ')
    for c in C:
        print(c, end=' ')
    print(K)

main()

Solution (Python):
def MI():
    return map(int,input().split())
def I():
    return int(input())
def LI():
    return [int(i) for i in input().split()]

m,k=MI()

if k>=2**m or (m,k)==(1,1):
    print(-1)
elif (m,k)==(1,0):
    print('0 0 1 1')
else:
    a=[]
    for i in range(2**m):
        if i!=k: a.append(i)
    ans=[k]+a+[k]+a[::-1]
    print(*ans)

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

if K == 0:
    ans = []
    for i in range(2 ** M):
        ans += [i, i]
    print(*ans)
elif M >= 2 and K < 2 ** M:
    b = list(range(2 ** M))
    b.remove(K)
    print(*(b + [K] + b[::-1] + [K]))
else:
    print(-1)

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

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

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

if m == 0:
    print(0, 0)
    exit()
elif m == 1:
    if k == 0:
        print(0, 0, 1, 1)
    else:
        
        print(-1)
else:
    t = list(range(0, k)) + list(range(k + 1, 2 ** m))
    ans = [k] + t + [k] + t[::-1]
    print(*ans)

Solution (Python):
import sys
from math import *
from fractions import gcd
readints=lambda:map(int, input().strip('\n').split())



m,k = readints()

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


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


ans = []
for i in range(2**m):
    if i!=k:
        ans.append(i)

ans.append(k)
i=2**m-1
while i>=0:
    if i!=k:
        ans.append(i)
    i-=1
ans.append(k)


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

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

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

if not anss:
    print(-1)
else:
    print(' '.join(map(str, anss)))

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)
  elif k==1:
    print(-1)
else:
  ris=[str(i) for i in range(2**m)]
  ris.remove(str(k))
  l=" ".join(ris)
  r=" ".join(ris[::-1])
  print(l,str(k),r,str(k))

Solution (Python):
from collections import deque

M,K = map(int,input().split())
if K >= 2**M or M==K==1:
    print(-1)
    exit()
if M == 1:
    print(0,0,1,1)
    exit()

ans = deque([K])
for n in range(2**M):
    if n==K: continue
    ans.append(n)
    ans.appendleft(n)
ans.appendleft(K)
print(*ans)

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:
    ans1 = [i for i in range(2**M) if i != K]
    ans2 = ans1[::-1]
    ans = [K]+ans1+[K]+ans2
    ans = ' '.join(str(i) for i in ans)
    print(ans)

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

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

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

if M == 1 and K == 1:
    print(-1)
    exit()

a = []
a.append(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):
m,k = map(int,input().split())

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

elif m == 0:
  print(" ".join(["0","0"]))

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

elif m == 1 and k == 1:
  print(-1)

elif m >= 2:
  b = [i for i in range(2**m)]
  b.remove(k)
  c = sorted(b,reverse = True)
  ans = b + [k] + c + [k]
  ans = list(map(str,ans))
  print(" ".join(ans))

Solution (Python):
def main():
    m, k = map(int, input().split())
    maximum = 2 ** m - 1

    if k==0:
        print(" ".join(map(str, range(0, maximum+1))), end=" ")
        print(" ".join(map(str, range(maximum, -1, -1))))
        return

    if m==1:
        print(-1)
        return

    if maximum < k:
        print(-1)
        return

    others = [i for i in range(1, maximum+1) if i!=k]
    print(0, k, 0, end=" ")
    print(" ".join(map(str, others)), k, " ".join(map(str, reversed(others))))


main()

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

MAX = 2 ** M

if K == 0:
  s = ' '.join(['{0} {0}'.format(i) for i in range(MAX)])
elif M == 1:
  s = '-1'
elif K < MAX:
  tmp = [i for i in range(MAX) if i != K]
  a = ' '.join(map(str, tmp))
  b = ' '.join(map(str, reversed(tmp)))
  s = '{0} {1} {0} {2}'.format(K, a, b)
else:
  s = '-1'

print(s)

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))
    print(" ".join(map(str,A+[K]+A[::-1]+[K])))

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

else:
  l=[]
  for iii in range(2**m):
    if iii!=k:
      l.append(iii)
  out=" ".join(map(str,l[::-1]+[k]+l+[k]))
  print(out)

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

if M <= 1 and K == 0:
    a = sum([[i, i] for i in range(2 ** M)], [])

elif 2 <= M and K < 2 ** M:
    a  = [K] + [i for i in range(2 ** M - 1, -1, -1) if i != K]
    a += [K] + [i for i in range(2 ** M) if i != K]

else:
    a = [-1]

print(' '.join(map(str, a)))

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

if K == 0:
    a  = [i for i in range(2 ** M - 1, -1, -1)]
    a += [i for i in range(2 ** M)]
elif 2 <= M and K < 2 ** M:
    a  = [K] + [i for i in range(2 ** M - 1, -1, -1) if i != K]
    a += [K] + [i for i in range(2 ** M) if i != K]

else:
    a = [-1]

print(' '.join(map(str, a)))

Solution (Python):
from itertools import permutations

M,K=map(int,input().split())
MX=2**(M)
if (M == 1 and K != 0) or K > MX-1:
    print(-1)
    exit()





















if K == 0:
    for i in range(MX):
        print(i,i,end=' ')
    print('')
else:
    print(K,end=' ')
    for i in range(MX):
        if i != K:
            print(i, end=' ')
    print(K, end=' ')
    for i in reversed(range(MX)):
        if i != K:
            print(i, end=' ')
    print('')

Solution (Python):
read = input 
rn = lambda :map(int, read().split())
m,k = rn()
import math
N = 2**(m) - 1 
r = [i for i in range(N+1)] 
if k > N:
    print(-1)


elif N == 1 and k == 1:
    print('-1')
elif k ==  0:
    for i in r:
        print(i, end=' ')
    r.reverse()
    for i in r:
        print(i, end=' ')
elif N == 2 and k == 1:
    print(-1)
else:
    for i in r:
        if i == k:continue
        print(i, end=' ')
    print(k, end=' ')
    r.reverse()
    for i in r:
        if i == k:continue
        print(i, end=' ')
    print(k, end=' ')

Solution (Python):
import sys

m, k = map(int, raw_input().split(" "))

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

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

    else:
        print(-1)
        sys.exit(0)

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

    else:
        print(-1)
        sys.exit(0)


for i in range(0, 2 ** m):
    if i != k:
        sys.stdout.write("%d " % i)

sys.stdout.write("%d " % k)

for i in range((2 ** m) -1, 0 - 1, -1):
    if i != k:
        sys.stdout.write("%d " % i)

print(k)

Solution (Python):
M, K = map(int,input().split())
if [M, K] == [0, 0]:
    print("0 0")
    exit(0)
if [M, K] == [1, 0]:
    print("0 0 1 1")
    exit(0)
if [M, K] == [1, 1]:
    print(-1)
    exit(0)
if 2**M <= K:
    print(-1)
    exit(0)

a = []
for k in range(2**M):
    if k != K:
        a.append(k)
ans = a+[K]+a[::-1]+[K]
print(*ans, sep=" ")

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

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