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):
def f_xor_matching(M, K):
    if K >= 2**M:
        return -1

    if M == 0:
        ans = [0, 0]
    elif M == 1:
        ans = [0, 0, 1, 1] if K == 0 else [-1]
    else:
        b = [k for k in range(2**M) if k != K]
        ans = b + [K] + b[::-1] + [K]
    return ' '.join(map(str, ans))

M, K = [int(i) for i in input().split()]
print(f_xor_matching(M, K))

Solution (Python):
n, k = map(int, raw_input().strip().split())

if k == 0:
    sz = 1 << n
    sz -= 1
    out = [' '.join([str(i), str(i)]) for i in xrange(sz + 1)]
    print ' '.join(out)
    exit()

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

if n < 2:
    print -1
    exit()

l = []
for i in xrange(m):
    if i == k: continue
    l.append(i)

l.append(k)
for i in xrange(m - 1, -1, -1):
    if i == k: continue
    l.append(i)
l.append(k)

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

Solution (Python):
m,k = map(int,input().split())
if m == 1 and k == 0:
  print("0 0 1 1")
  quit()
n=2**m
k += (n == 2 and k == 1)
p=list(range(n))
print(" ".join([str(t) for t in p[:k]+p[k::-1]+p[:k:-1]+p[k:]]) if k<n else -1)

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(M, K):
    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:

            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, '', end='')

        else:
            print(-1)


def main():
    M, K = read_int_n()
    (slv(M, K))


if __name__ == '__main__':
    main()

Solution (Python):
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools, random
from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right; sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; ansli = []; tmpli = []; candili = []
eps = 1.0 / 10 ** 10; mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]; ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]; ddn9 = ddn + [(0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]
def mi(n): return [wi() for _ in range(n)]
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]

m, k = wi()

if 2 ** m < k:
    print(-1)
elif k == 0:
    for i in range(2 ** m):
        for j in range(2):
            ansli.append(i)
    for i in range(len(ansli)):
        print(ansli[i], "", end="")
else:
    for i in range(2 ** m):
        if i != k:
            tmp ^= i
    if tmp == k:
        ansli.append(k)
        for i in range(2 ** m):
            if i != k:
                ansli.append(i)
        ansli.append(k)
        for i in range(2 ** m - 1, -1, -1):
            if i != k:
                ansli.append(i)
        for i in range(len(ansli)):
            print(ansli[i],"",end="")
    else:
        print(-1)

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 K<=(2**M-1):
    r = list(range(2**M))
    r = r[:K]+r[K+1:]
    ans = [K]+r+[K]+r[::-1]
    print(*ans)
else:
    print(-1)

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>=2**m:
        print(-1)
    else:
        print(k,end=' ')
        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=' ')

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')
    else:
        print(-1)
    exit()

ans = [k]
left = []
for i in range(2**m):
    if i == k:
        continue
    left.append(i)
right = left[::-1]
ans = left + ans + right + ans
print(*ans)

Solution (Python):
def main():
    M, K = map(int, input().split())
    N = 2**M
    if M == 1:
        if K == 0:
            print(*[0, 0, 1, 1])
        else:
            print(-1)
        return
    if K >= N:
        print(-1)
        return
    ans = [x for x in range(N) if x != K]
    ans = ans + [K] + ans[::-1] + [K]
    print(*ans)


if __name__ == "__main__":
    main()

Solution (Python):
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = 10**18
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

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

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

Solution (Python):
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = 10**18
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

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

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

Solution (Python):
def solve(M, K):
    if K == 0:
        r = [i for i in range(0, 2 ** M)]
        return " ".join(str(c) for c in r + r[::-1])
    elif M > 1 and K < (2 ** M):
        r = [i for i in range(0, (2 ** M)) if i != K]
        return " ".join(str(c) for c in r[::-1] + [K] + r + [K])
    else:
        return "-1"
 
 
if __name__ == "__main__":
    M, K = tuple(map(int, input().split(" ")))
    print(solve(M, K))

Solution (Python):
M, K = map(int,input().split())
if M == 1 and K == 1:
    print(-1)
elif K == 0:
    for i in range(2**M):
        print(i,end=" ")
        print(i,end=" ")
elif 2**M <= K:
    print(-1)
else:
    for i in range(2**M):
        if i != K:
            print(i,end=" ")
    print(K, end=" ")
    for i in reversed(range(2**M)):
        if i != K:
            print(i,end=" ")
    print(K, end=" ")

Solution (Python):
def solve(M, K):
    if K == 0:
        r = [i for i in range(0, 2 ** M)]
        return " ".join(str(c) for c in r + r[::-1])
    elif M > 1 and K < (2 ** M):
        r = [i for i in range(0, (2 ** M)) if i != K]
        return " ".join(str(c) for c in r[::-1] + [K] + r + [K])
    else:
        return "-1"
 
 
if __name__ == "__main__":
    M, K = tuple(map(int, input().split(" ")))
    print(solve(M, K))

Solution (Python):
M, K = map(int,input().split())
if M == 1 and K == 1:
    print(-1)
elif K == 0:
    for i in range(2**M):
        print(i,end=" ")
        print(i,end=" ")
elif 2**M <= K:
    print(-1)
else:
    for i in range(2**M):
        if i != K:
            print(i,end=" ")
    print(K, end=" ")
    for i in reversed(range(2**M)):
        if i != K:
            print(i,end=" ")
    print(K, end=" ")

Solution (Python):
M, K = map(int,input().split())
if M == 1 and K == 1:
    print(-1)
elif K == 0:
    for i in range(2**M):
        print(i,end=" ")
        print(i,end=" ")
elif 2**M <= K:
    print(-1)
else:
    for i in range(2**M):
        if i != K:
            print(i,end=" ")
    print(K, end=" ")
    for i in reversed(range(2**M)):
        if i != K:
            print(i,end=" ")
    print(K, end=" ")

Solution (Python):
def main():
    M, K = map(int, input().split())
    N = 2**M
    if M == 1:
        if K == 0:
            print(*[0, 0, 1, 1])
        else:
            print(-1)
        return
    if K >= N:
        print(-1)
        return
    ans = [x for x in range(N) if x != K]
    ans = ans + [K] + ans[::-1] + [K]
    print(*ans)


if __name__ == "__main__":
    main()

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

Solution (Python):
import sys
from collections import deque

sys.setrecursionlimit(10000)
INF = float('inf')

assert 2 ** 18 == 262144




















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

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

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

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

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

Solution (Python):
import sys
from collections import deque

sys.setrecursionlimit(10000)
INF = float('inf')

assert 2 ** 18 == 262144




















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

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

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

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

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

Solution (Python):
def solve(M, K):
    if K == 0:
        r = [i for i in range(0, 2 ** M)]
        return " ".join(str(c) for c in r + r[::-1])
    elif M > 1 and K < (2 ** M):
        r = [i for i in range(0, (2 ** M)) if i != K]
        return " ".join(str(c) for c in r[::-1] + [K] + r + [K])
    else:
        return "-1"


if __name__ == "__main__":
    M, K = tuple(map(int, input().split(" ")))
    print(solve(M, K))

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

N = 1 << M

if M == 0:
	if 0 < K:
		print(-1)
	else:
		print('0 0')
elif M == 1:
	if 0 < K:
		print(-1)
	else:
		print('0 0 1 1')
else:
	if N <= K:
		print(-1)
	else:
		RK = K
		A = [RK]
		B = [i for i in range(N) if i != RK]
		print(' '.join((
			' '.join(map(str, reversed(A))),
			' '.join(map(str, reversed(B))),
			' '.join(map(str, A)),
			' '.join(map(str, B)))))

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

arr = list(range(2**M))
if K == 0:
  print(' '.join(list(map(str, list(sorted(arr + arr))))))
  exit()

arr2 = arr[:K] + arr[K+1:]
print(' '.join(list(map(str, arr2 + [K] + arr2[::-1] + [K]))))

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("0 0 1 1")
else:
    x_list = list(range(2**M))
    x_k_list = [x for x in x_list if x != K]
    res_list = x_k_list + [K] + list(reversed(x_k_list)) + [K]
    print(" ".join([str(r) for r in res_list]))

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

Solution (Python):
m, k = map(int,input().split())
if m == 0:
  if k == 0:
    print("0 0")
  else:
    print(-1)
  quit()
  
if m == 1:
    if k == 0:
        print("0 0 1 1")
    else:
        print(-1)
    quit()

n = 2**m
if k >= n:
    print(-1)
    quit()
    
a = list(range(0,k)) + [k] + list(range(0,k))[::-1] + list(range(k+1,n))[::-1]  + [k] + list(range(k+1,n))
b = [str(t) for t in a]
print(" ".join(b))

Solution (Python):
M, K = map(int, input().split())
if K > 2 ** M - 1:
  print(-1)
elif M == 1 and K == 0:
  print('0 0 1 1')
elif M == 1 and K == 1:
  print(-1)
else:
  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(' '.join(map(str, ans)))

Solution (Python):
M,K=map(int,input().split())
if K==0:
    L=[i for i in range(2**M)]
    L=L+L
    L.sort()
    ans="0"
    for i in range(1,len(L)):
        ans+=" "+str(L[i])
    print(ans)
elif K<2**(M):
    if M==0 or M==1:
        print(-1)
    else:
        A="0 "+str(K)+" 0"
        for i in range(1,2**(M)):
            if i==K:
                pass
            else:
                A+=" "+str(i)
        A+=" "+str(K)
        for i in range(1,2**(M)):
            if (2**(M)-i)==K:
                pass
            else:
                A+=" "+str(2**(M)-i)
        print(A)
else:
    print(-1)

Solution (Python):
def solve(m,k):
    n=2**m
    if k>n-1:
        return [-1]
    if k==0:
        Ret=[]
        for i in range(n):
            Ret.append(i); Ret.append(i)
        return Ret
    if m==1:
        return [-1]
    Used=[False]*n
    Used[0]=True; Used[k]=True
    Pair=[]
    for i in range(1,n):
        if Used[i]:
            continue
        Pair.append([i,k^i])
        Used[i]=True; Used[k^i]=True
    A=[]
    for a,b in Pair:
        A.append(a); A.append(b)
    Ret=A+[0,k,0]+A[::-1]+[k]
    return Ret

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

Solution (Python):
m, k = map(int, input().split())
if m == 1:
    if k == 0:
        print('0 0 1 1')
    else:
        print(-1)
else:
    if k < 2 ** m:
        for i in range(2 ** m):
            if i != k:
                print(i, end = ' ')
        print(k, end = ' ')
        for i in reversed(range(2 ** m)):
            if i != k:
                print(i, end = ' ')
        print(k)
    else:
        print(-1)

Solution (Python):
def solve(m,k):
    if m==0:
        if k==0:
            return [0,0]
        return [-1]
    if m==1:
        if k==0:
            return [0,0,1,1]
        return [-1]
    if k>2**m-1:
        return [-1]
    n=2**m
    if k==0:
        Ret=[]
        for i in range(n):
            Ret.append(i); Ret.append(i)
        return Ret
    Used=[False]*n
    Used[0]=True; Used[k]=True
    Pair=[]
    for i in range(1,n):
        if Used[i]:
            continue
        Pair.append([i,k^i])
        Used[i]=True; Used[k^i]=True
    A=[]
    for a,b in Pair:
        A.append(a); A.append(b)
    Ret=A+[0,k,0]+A[::-1]+[k]
    return Ret

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

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

if K >= 2 ** M:
    print(-1)
elif K == 0:
    ans = []
    x = range(0, 2 ** M)
    y = range(0, 2 ** M)
    for xx, yy in zip(x, y):
        ans.append(xx)
        ans.append(yy)
    print(*ans)
else:
    if M == 1 and K == 1:
        print(-1)
        exit()
    x = [i for i in range(0, 2 ** M) if i != K]
    ans = [K] + x + [K] + list(reversed(x))
    print(*ans)

Solution (Python):
def solve(m,k):
    n=2**m
    if k>n-1:
        return [-1]
    if k==0:
        Ret=[]
        for i in range(n):
            Ret.append(i); Ret.append(i)
        return Ret
    if m==1:
        return [-1]
    Used=[False]*n
    Used[0]=True; Used[k]=True
    Pair=[]
    for i in range(1,n):
        if Used[i]:
            continue
        Pair.append([i,k^i])
        Used[i]=True; Used[k^i]=True
    A=[]
    for a,b in Pair:
        A.append(a); A.append(b)
    Ret=A+[0,k,0]+A[::-1]+[k]
    return Ret

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

Solution (Python):
m, k = map(int, input().split())
if k >= 2 ** m:
	print("-1")
elif k == 0:
	res = []
	for i in range(2 ** m):
		res += [i, i]
	print(" ".join(map(str, res)))
elif m == 0:
	print("0 0")
elif m == 1:
	if k == 0:
		print("0 0 1 1")
	else:
		print(-1)
else:
	used = set()
	pair = []
	for i in range(2 ** m):
		if i not in used:
			used.add(i)
			used.add(i ^ k)
			pair.append((i, i ^ k))
	res = []
	for i in range(0, len(pair), 2):
		res += [pair[i][0], pair[i][1], pair[i + 1][0], pair[i + 1][1],
				pair[i][1], pair[i][0], pair[i + 1][1], pair[i + 1][0]]
	print(" ".join(map(str, res)))

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

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

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

X = [a for a in range(2 ** M) if (a != 0) and (a != K)]
N = len(X)
L = X[: N // 2][::-1] + [0] + [K] + X[: N // 2]
R = X[N // 2:] + [K] + [0] + X[N // 2:][::-1]
ans = L + R


zl, zr = [i for i, a in enumerate(ans) if a == 0]
check = 0
for a in ans[zl : zr]:
    check ^= a

if check == K:
    print(*ans, sep=' ')
else:
    print(-1)

Solution (Python):




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

def solve(M,K):
  if M == 0:
    if K == 0:
      return '0 0'
    else:
      return '-1'
  if M == 1:
    if K == 0:
      return '0 1 1 0'
    else:
      return '-1'
  U = 1<<M
  if K >= U:
    return -1
  other = [str(x) for x in range(U) if x != K]
  result = other + [str(K)] + other[::-1] + [str(K)]
  return ' '.join(result)

answer = solve(M,K)
print(answer)

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

if K >= 2 ** M:
    print(-1)
elif K == 0:
    ans = []
    x = range(0, 2 ** M)
    y = range(0, 2 ** M)
    for xx, yy in zip(x, y):
        ans.append(xx)
        ans.append(yy)
    print(*ans)
else:
    if M == 1 and K == 1:
        print(-1)
        exit()
    t = 0
    for i in range(1, 2 ** M):
        if i == K: continue
        t ^= i
    if t == K:
        x = [i for i in range(0, 2 ** M) if i != K]
        ans = [K] + x + [K] + list(reversed(x))
        print(*ans)
    else:
        print(-1)

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

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


xx = 0
for i in range(2**m):
    xx = xx ^ i

if k == 0:
    arr = [0] * (2 ** (m+1))
    for i in range(2**m):
        arr[2*i] = i
        arr[2*i+1] = i
    print(" ".join([str(x) for x in arr]))
elif xx != 0 or k >= 2 ** m:
    print(-1)
else:
    arr = [0] * (2 ** (m+1))
    f = (2 ** (m+1))
    arr[0] = k
    arr[f//2] = k
    pt1 = f // 2 - 1
    pt2 = f // 2 + 1
    curr = 0
    for i in range((f - 2) // 2):
        if (curr == k):
            curr += 1
        arr[pt1] = curr
        arr[pt2] = curr
        pt1 -= 1
        pt2 += 1 
        curr += 1
    print(" ".join([str(x) for x in arr]))

Solution (Python):
from functools import reduce
from operator import xor
M, K = map(int, input().split())
if M == 1 and K == 1:
    print(-1)
elif not K:
    print(*(list(range(2**M)) + list(range(2**M))[::-1]))
elif not 0 <= K <= 2**M -1:
    print(-1)
else:
    T = [i for i in range(2**M) if i != K]
    if K != reduce(xor, T):
        print(-1)
    else:
        print(*([K] + T + [K] + T[::-1]))

Solution (Python):
import sys
sys.setrecursionlimit(20000000)

m,k = map(int,input().split())
if k == 0:
    ans = []
    for i in range(2**(m)):
        ans.append(i)
        ans.append(i)
    print(" ".join(map(str,ans)))
    exit()
if k > (2**(m))-1:
    print(-1)
    exit()
a = 0
for i in range(2**m):
    if i != k:
        a ^= i
if a != k:
    print(-1)
    exit()
ans = []
for i in range(2**m):
    if i == k:
        continue
    ans.append(str(i))
ans = ans + [str(k)] + ans[::-1] + [str(k)]
print(" ".join(ans))

Solution (Python):




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

def solve(M,K):
  if M == 0:
    if K == 0:
      return '0 0'
    else:
      return '-1'
  if M == 1:
    if K == 0:
      return '0 1 1 0'
    else:
      return '-1'
  U = 1<<M
  if K >= U:
    return -1
  other = [str(x) for x in range(U) if x != K]
  result = other + [str(K)] + other[::-1] + [str(K)]
  return ' '.join(result)

answer = solve(M,K)
print(answer)

Solution (Python):
import sys
range = xrange
input = raw_input

m,k = [int(x) for x in input().split()]

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

if k==0:
    A = list(range(2**m))
    print ' '.join(str(a) for a in (A + A[::-1]))
    sys.exit()

A = [i for i in range(2**m) if i != k]

A = A + [k] + A[::-1] + [k]

print ' '.join(str(a) for a in A)

Solution (Python):
import sys

inf = 10 ** 18

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

tmp = 0
notK = []
for i in range(1 << M):
    if i == K: continue
    tmp ^= i
    notK.append(i)
if K == 0:
    ans = []
    for i in range((1 << M)):
        ans.append(i)
    for i in range((1 << M)):
        ans.append((1 << M) - 1 - i)
    
    for i, ansi in enumerate(ans):
        if i > 0: print(' ', end='')
        print(ansi, end='')
    print()
elif tmp != K:
    print(-1)
else:
    ans = []
    ans.append(notK[0])
    ans.append(K)
    ans.append(notK[0])
    for i in range(1, (1 << M) - 1):
        ans.append(notK[i])
    ans.append(K)
    for i in range(1, (1 << M) - 1):
        ans.append(notK[(1 << M) - 1 - i])
    
    for i, ansi in enumerate(ans):
        if i > 0: print(' ', end='')
        print(ansi, end='')
    print()

Solution (Python):
import sys
range = xrange
input = raw_input

m,k = [int(x) for x in input().split()]

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

if k==0:
    A = list(range(2**m))
    print ' '.join(str(a) for a in (A + A[::-1]))
    sys.exit()

A = [i for i in range(2**m) if i != k]

A = A + [k] + A[::-1] + [k]

if len(A)!=2**(m+1):
    print -1
    sys.exit()

xorsum = [0]
for a in A:
    xorsum.append(xorsum[-1]^a)

index = [-1]*(2**m)
for i in range(len(A)):
    if index[A[i]] == -1:
        index[A[i]] = i
    else:
        j = index[A[i]]
        if (xorsum[i+1]^xorsum[j])!=k:
            print -1
            sys.exit()

print ' '.join(str(a) for a in A)

Solution (Python):
m,k = map(int,input().split())
if k == 0:
    l = [i // 2 for i in range(2 ** (m + 1))]
    print(*l)
    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()

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

l = [0]
for i in range(2 ** (m - 1) - 1):
    l.append(2 ** (m - 1) - i)
for i in range(2 ** (m - 1)):
    l.append(i + 1)
for i in range(2 ** m):
    if i == 0:
        l.append(0)
    elif i == 2 ** (m - 1):
        l.append(l[i])
    else:
        l.append(l[i] + 2 ** (m - 1) - 1)

if k == 1:
    print(*l)
    exit()

for i in range(len(l)):
    if l[i] == 1:
        l[i] = k
    elif l[i] == k:
        l[i] = 1
print(*l)

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

s = 0
for i in range(m2):
  s ^= i


ans = [0 for i in range(m2 * 2)]
if K == 0:
  for i in range(m2):
    ans[i] = i
    ans[m2 * 2 - i - 1] = i
    
  print(" ".join(map(str, ans)))
elif K < m2 and s == 0:
  ans[0] = K
  ans[m2] = K
  for i in range(m2 - 1):
    num = i
    if num >= K:
      num += 1
    ans[i + 1] = num
    ans[m2 * 2 - i - 1] = num

  print(" ".join(map(str, ans)))
else:
  print(-1)

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

Solution (Python):
def solve(m,k):
    if m==0:
        if k==0:
            return [0,0]
        return [-1]
    if m==1:
        if k==0:
            return [0,0,1,1]
        return [-1]
    if k>2**m-1:
        return [-1]
    n=2**m
    if k==0:
        Ret=[]
        for i in range(n):
            Ret.append(i); Ret.append(i)
        return Ret
    Used=[False]*n
    Used[0]=True; Used[k]=True
    Pair=[]
    for i in range(1,n):
        if Used[i]:
            continue
        Pair.append([i,k^i])
        Used[i]=True; Used[k^i]=True
    A=[]
    for a,b in Pair:
        A.append(a); A.append(b)
    Ret=A+[0,k,0]+A[::-1]+[k]
    return Ret

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

Solution (Python):



n,k=[int(i) for i in input().split()]

if n==0:
    if k==0:
        print("0 0")
    else:
        print(-1)
elif n==1:
    if k==0:
        print("0 0 1 1")
    else:
        print(-1)
else:
    if k >= 2**(n):
        print(-1)
    elif k==0:
        a = list(range(2**n))
        ans = a + list(reversed(a))
        print(*ans)
    else:
        a = [i for i in range(1,2**(n)) if i != k]
        ans = a + [k] + list(reversed(a)) + [0,k,0]
        print(*ans)

Solution (Python):
from functools import reduce
from operator import xor
from itertools import chain

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

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

    if M >= 2:
        def it():
            for i in reversed(range(2**M)):
                if i != K:
                    yield i
            yield K
            for i in range(2**M):
                if i != K:
                    yield i
            yield K
        print(*it())
    elif M == 1:
        if K == 0:
            print(0,0,1,1)
        else:
            print(-1)
    else:
        print(0, 0)

if __name__ == '__main__':
    main()

Solution (Python):
M,K=map(int,input().split())
if 2**M<=K:
  print(-1)
  exit()
if K==0:
  ans=[]
  for i in range(2**M):
    ans.append(str(i))
    ans.append(str(i))
  print(" ".join(ans))
  exit()
if M==1:
  print(-1)
  exit()
ans=["0"]
for i in range(1,2**M):
  if i!=K:
    ans.append(str(i))
ans.append("0")
ans.append(str(K))
for i in range(1,2**M)[::-1]:
  if i!=K:
    ans.append(str(i))
ans.append(str(K))
print(" ".join(ans))

Solution (Python):
from math import *



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


def core():
    if 2**M <= K:
        return [-1]

    if M==0:
        return [0,0]

    if M==1:
        if K==0:
            return [0,0,1,1]
        if K==1:
            return [-1]

    if K==0:
        re = []
        for i in range(2**M):
            re.append(i)
            re.append(i)
        return re

    re = []
    for i in range(2**M):
        if i!=K:
            re.append(i)
    re.append(K)
    for i in range(2**M-1,-1,-1):
        if i!=K:
            re.append(i)
    re.append(K)
    return re


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

Solution (Python):

def main():
    buf = input()
    buflist = list(buf.split())
    M = int(buflist[0])
    K = int(buflist[1])
    numbers = []
    if K == 0:
        for i in range(2 ** M):
            numbers.append(i)
            numbers.append(i)
        print(' '.join(map(str, numbers)))
        return
    if K > 2 ** M - 1:
        print(-1) 
        return
    xor_result = 0
    for i in range(2 ** M):
        if i == K:
            continue
        xor_result = xor_result ^ i
    if xor_result != K:
        print(-1) 
        return
    for i in range(2 ** M):
        if i != K:
            numbers.append(i)
    numbers.append(K)
    for i in range(2 ** M - 1, -1, -1):
        if i != K:
            numbers.append(i)
    numbers.append(K)
    print(' '.join(map(str, numbers)))


if __name__ == '__main__':
    main()

Solution (Python):
M, K = map(int, input().split())
if K > 2 ** M - 1:
  print(-1)
elif M == 1 and K == 0:
  print('0 0 1 1')
elif M == 1 and K == 1:
  print(-1)
else:
  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(' '.join(map(str, ans)))

Solution (Python):
import sys
M,K=map(int,input().split())
if 2**M<=K:
    print(-1)
    sys.exit()
if M==1:
    if K==0:
        print(0,0,1,1)
    else:
        print(-1)
    sys.exit()
L=[i for i in range(2**M)]
L+=[0]
M=[i for i in range(2**M-1,0,-1)]
L+=M

for i in range(len(L)):
    L[i]^=K
print(' '.join(map(str,L)))