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 solve():
    M, K = [int(_) for _ in raw_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:
        MAX = 1 << M
        if K >= MAX:
            print '-1'
        else:
            arr = list(range(K))
            arr.extend(list(range(K + 1, MAX)))
            arr_rev = arr[::-1]
            arr.append(K)
            arr.extend(arr_rev)
            arr.append(K)
            for ele in arr:
                print ele,

if __name__ == '__main__':
    solve()

Solution (Python):
import copy
M, K =map(int,input().split())
if M == 1:
    if K == 0:
        print('0 0 1 1')
    else:
        print(-1)
elif K == 0:
    ANSL = []
    for i in range(2**M):
        ANSL.append(str(i))
        ANSL.append(str(i))
    ANS = ' '.join(ANSL)
    print(ANS)
elif K <= 2**M-1:
    LI = []
    for i in range(2**M):
        LI.append(2**M-1-i)
    LI.pop(2**M-K-1)
    CI = copy.copy(LI)
    CI.sort()
    AN = [K]+LI+[K]+CI
    ANSL =[str(s) for s in AN]
    ANS = ' '.join(ANSL)
    print(ANS)
else:
    print(-1)

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


if 2 ** M <= K or K == 1 and M == 1:
    print(-1)
elif K == 0:
    ary = [i//2 for i in range(MAX_A*2)]
    print(' '.join(map(str, ary)))
else:
    
    ary = []
    
    ary_asc = [i for i in range(MAX_A) if i != K]
    ary_dec = [i for i in range(MAX_A-1,-1,-1) if i != K]
    ary.extend(ary_dec)
    ary.extend([K])
    ary.extend(ary_asc)
    ary.extend([K])

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

Solution (Python):

import copy
import random
import bisect 
import fractions 
import math
import sys

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

M,K = map(int,input().split())
ans = False
if M == 0:
    if K == 0:
        ans = [0,0]
    else:
        print(-1)

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

else:
    if K < 2**M:
        b = [int(i) for i in range(2**M)]
        b.remove(K)
        ans = []
        ans += b
        ans += [K]
        b.reverse()
        ans += b
        ans += [K]

    else:
        print(-1)
if ans == False:pass
else:
    for i in range(len(ans)):
        print(str(ans[i])+" ",end="")
    print("")

Solution (Python):
M, K = map(int, input().split())
if 2**M <= K:
    print("-1")
else:
    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:
        ret = ""
        for i in range(2**M):
            if i != K:
                ret += str(i)+" "
        ret += str(K) + " "
        for i in range(2**M-1, -1, -1):
            if i != K:
                ret += str(i)+" "
        ret += str(K)
        print(ret)

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

ans = []
if M == 0 or M == 1:
    if K == 0:
        for i in range(2**M):
            ans.append(str(i))
            ans.append(str(i))
    else:
        ans.append('-1')
elif K >= 2**M:
    ans.append('-1')
else:
    for i in range(2**M):
        if i != K:
            ans.append(str(i))
    ans.append(str(K))
    for i in reversed(range(2**M)):
        if i != K:
            ans.append(str(i))
    ans.append(str(K))

print(' '.join(ans))

Solution (Python):

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


ans = (
    '-1' if K >= 2**M or M == K == 1 else
    '0 0' if M == 0 else
    '0 0 1 1' if M == 1 else
    '{} {} {} {}'.format(
        K,
        ' '.join(
            str(i)
            for i in range(2**M)
            if i != K
        ),
        K,
        ' '.join(
            str(i)
            for i in range(2**M - 1, -1, -1)
            if i != K
        ),
    )
)


print(ans)

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 0<=K<2**M:
        X=[i^K for i in range(2**M)]+[K]+[i^K for i in range(1,2**M)][::-1]
        print(" ".join([str(i) for i in X]))
    else:
        print(-1)

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

if 2**m <= k:
    print(-1)
elif m == 0:
    if k == 0:
        print(0,0)
    else:
        print(-1)
elif m == 1:
    if k == 0:
        print('0 0 1 1')
    else:
        print(-1)
else:
    ans = []
    append = ans.append
    for i in range(2**m):
        if i == k:
            continue
        else:
            append(i)
    append(k)
    for i in range(2**m-1,-1,-1):
        if i == k:
            continue
        else:
            append(i)
    append(k)

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

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

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

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

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

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

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

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

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

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

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

Solution (Python):



def main():
    m, k = list(map(int, input().split()))
    if k >= 2**m:
        print(-1)
        return
    if m == 0:
        if k == 0:
            print('0 0')
        else:
            print(-1)
        return
    if m == 1:
        if k == 0:
            print('1 0 0 1')
        else:
            print(-1)
        return
    result = [i for i in range(2**m) if i != k]
    b = list(map(str, result))
    c = reversed(b)
    print(' '.join(b), k, ' '.join(c), k)


if __name__ == '__main__':
    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)
elif k<2**m:
    l=[i for i in range(2**m)]
    l.remove(k)
    l_=l.copy()
    l_ = l_ + [k] + l_[::-1] + [k]
    print(' '.join(map(str,l_)))
else:
    print('-1')

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

if k==0:
    x=[[i]*2 for i in range(2**m)]
    for i in x:
        print(*i,end=" ")
elif m==1:
    print(-1)
elif 2**m<=k:
    print(-1)
else:
    for i in reversed(range(2**m)):
        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())

def xor_match(M, K) :
	if K >= 2 ** M :
		return '-1' 

	elif (M, K) == (0, 0) :
		return '0 0'

	elif (M, K) == (1, 0) :
		return '0 0 1 1'

	elif (M, K) == (1, 1) :
		return '-1'

	init = 1

	if K == 0 :
		p_left = [1, 0, 1]
		init = 2
	else :
		p_left = [0, K, 0]

	p_right = []
	for i in range(init, 2**M) :
		if i == K :
			continue
		
		p_right.append(i)

	p = map(str, p_left + p_right + [K] + p_right[::-1])
	return ' '.join(p)

print(xor_match(M, K))

Solution (Python):
m, k = [int(item) for item in input().split()]

if m == 0:
    if k == 0:
        print("0 0")
    else:
        print(-1)
        exit()
elif m == 1:
    if k == 0:
        print("0 0 1 1")
    else:
        print(-1)
        exit()
else:
    if k >= 2**m:
        print(-1)
        exit()
    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):
m, k = map(int, input().split())
l = int(2 ** (m + 1))
p = 2 ** m
if m == 0 or m == 1:
    if k == 0:
        if m == 0:
            print('0 0')
        else:
            print('0 0 1 1')
    else:
        print('-1')
else:
    if k >= p:
        print('-1')
    else:
        ans = []
        tmp = list(range(p))
        tmp.remove(k)
        ans.extend(tmp)
        ans.append(k)
        ans.extend(list(reversed(tmp)))
        ans.append(k)
        print(*ans)

Solution (Python):
m, k = map(int, input().split())
l = int(2 ** (m + 1))
p = 2 ** m
if m == 0 or m == 1:
    if k == 0:
        if m == 0:
            print('0 0')
        else:
            print('0 0 1 1')
    else:
        print('-1')
else:
    if k >= p:
        print('-1')
    else:
        ans = []
        tmp = list(range(p))
        tmp.remove(k)
        ans.extend(tmp)
        ans.append(k)
        ans.extend(list(reversed(tmp)))
        ans.append(k)
        print(*ans)

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

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

if M == 0:
    if K == 0:
        print('0 0')
elif M == 1:
    if K == 0:
        print('0 0 1 1')
    if K == 1:
        print(-1)
else:
    b = [str(i) for i in range(2**M) if i != K]
    c = [str(i) for i in range(2**M-1, -1, -1) if i != K]
    print(' '.join(b) + ' ' + str(K) + ' ' + ' '.join(c) + ' ' + str(K))

Solution (Python):
from operator import xor
from itertools import repeat

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

if K >= 2 ** M:
    print(-1)
elif K == 0:
    print(*(i // 2 for i in range(2 ** (M + 1))))
else:
    if M == 1:
        print(-1)
    else:
        t = ([0] + list(reversed(range(1, 2 ** M))) + list(range(2 ** M)))
        print(*map(xor, t, repeat(K)))

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

if M == 1:
    if K == 0:
        print("1 1 0 0")
    else:
        print(-1)
elif 2**M > K:
    X = list(range(K)) + list(range(K+1, 2**M))
    ans = " ".join(map(str, X + [K] + X[::-1] + [K]))
    print(ans)
else:
    print(-1)

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

if 2**M <= K:
    print(-1)
elif M == 1:
    if K == 0:
        print("1 1 0 0")
    else:
        print(-1)
else:
    X = list(range(K)) + list(range(K+1, 2**M))
    ans = " ".join(map(str, X + [K] + X[::-1] + [K]))
    print(ans)

Solution (Python):

import itertools
from collections import Counter
from collections import defaultdict
import bisect

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

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

    if 2 ** M <= K:
        print('-1')
    else:
        a = [i for i in range(2 ** M) if i != K]
        b = reversed(a)
        ans = ' '.join(map(str, a)) + ' ' + str(K) + ' ' + ' '.join(map(str, b)) + ' ' + str(K)
        print(ans)

if __name__ == '__main__':
    main()

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

if pow(2,M) <= K or (M,K) == (0,1) or (M,K) == (1,1):
    print(-1)
elif (M,K) == (0,0):
    print("0 0")
elif (M,K) == (1,0):
    print("0 0 1 1")
else:
    ans = [str(i) for i in range(pow(2,M)) if i != K]
    ans = ans + [str(K)] + ans[::-1] + [str(K)]
    print(" ".join(ans))

Solution (Python):


import sys
import math

import array
import bisect
import collections
from collections import Counter, defaultdict
import fractions
import heapq
import re

sys.setrecursionlimit(1000000)


def array2d(dim1, dim2, init=None):
    return [[init for _ in range(dim2)] for _ in range(dim1)]

def argsort(l, reverse=False):
    return sorted(range(len(l)), key=lambda i: l[i], reverse=reverse)

def argmin(l):
    return l.index(min(l))

def YESNO(ans, yes="YES", no="NO"):
    print([no, yes][ans])

II = lambda: int(input())
MI = lambda: map(int, input().split())
MIL = lambda: list(MI())
MIS = lambda: input().split()


def main():
    M, K = MI()

    if M == 1 and K == 1:
        return -1
    if K >= 2**M:
        return -1
    if K == 0:
        ans = []
        for i in range(0, 2**M):
            ans.append(i)
            ans.append(i)
        return " ".join(map(str, ans))

    ans = []
    ans.append(K)
    for i in range(0, 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)
    return " ".join(map(str, ans))


if __name__ == "__main__":
    print(main())

Solution (Python):
import sys

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

    if K >= 2**M:
        return [-1]

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

    
    a = list(range(K)) + list(range(K+1, 2**M))

    
    b = a[::-1]

    return a + [K] + b + [K]


if __name__ == '__main__':
    print(*main())

Solution (Python):
M, K = map(int, input().split())
if M == 1 and K == 0:
    print("0 0 1 1")
elif M == 1 and K == 1:
    print(-1)
elif 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 - 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())


if M == 1 and K == 1:
    print(-1)
elif M==1 and K == 0:
    print("0 0 1 1")
elif K >= 2**M:
    print(-1)
else:
    M = [i for i in range(2**M)]
    M.remove(K)
    ans = M + [K] + M[::-1] + [K]
    anstr = ""
    for a in ans:
        anstr += str(a) + " "
    print(anstr[:-1])

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

n = 2 ** m

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

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

ans = []
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)

ans.append(k)

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

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

if m == 1 and k == 0:
    print("0 0 1 1")
    quit()
k += (2**(m) == 2 and k == 1)
if k< 2**(m):
    l = list(range(2**(m)))
    r = l[::-1]
    tep = [k]
    res=l[:k] + l[k+1:] +tep + r[:2**m-k-1] + r[2**m-k:] + tep
    s = ""
    for j in res:
        s+=str(j)+" "
    print(s[:-1])
else:
    print(-1)

Solution (Python):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

M,K=MAP()

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

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

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

ans=[]
for i in range(2**M):
    if i!=K:
        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)

Solution (Python):
import sys

input = sys.stdin.readline
M, K = map(int, input().split())

ma = 2 ** M

if M == 0:
    if K > 0:
        print(-1)
    else:
        print('0 0')

elif M == 1:
    if K != 0:
        print(-1)
    else:
        print('0 0 1 1')

elif K >= ma:
    print(-1)

else:
    arr = [x for x in range(ma) if x != K]

    for i in arr:
        print(i, end=' ')
    print(K, end=' ')

    for i in arr[::-1]:
        print(i, end=' ')
    print(K)

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

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

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

x, y = [i for i in range(k)], [j for j in range(k+1, 2**m)]
l = x+y
r = list(reversed(l))
ans = l+[k]+r+[k]
print(*ans)

Solution (Python):




def main():
    
    m, k = [int(s) for s in input().split()]
    n = 2**m
    
    if k >= n:
        print('-1')
        return
    elif m == 0 and k == 0:
        print('0 0')
        return
    elif m == 1 and k == 0:
        print('0 0 1 1')
        return
    elif m == 1 and k == 1:
        print('-1')
        return
    
    l = [i for i in range(n) if i!=k]
    ans = []
    ans.extend(l)
    ans.append(k)
    ans.extend(reversed(l))
    ans.append(k)
    
    print(' '.join(map(str, ans)))

if __name__ == '__main__':
    main()

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

def createL(k):
    L = []
    for i in range(2**M):
        if i!=k: L.append(i)
    return L,L[:][::-1]

S = []
if K>=(2**M):
    print(-1)
elif M==0:
    print("0 0")
elif M==1:
    if K==1: print(-1)
    else: print("0 0 1 1")
else:
    L,Lrev = createL(K)
    print(" ".join(str(i)for i in L+[K]+Lrev+[K]))

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

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")
    elif k == 1:
        print(-1)
else:
    l = list(range(2**m))
    l.remove(k)
    ret = l + [k] + l[::-1] + [k]
    print(*ret)

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

max_val = 2 ** M

ans = []
if K < max_val:
    if M == 0:
        ans = [0, 0]
    elif M == 1:
        if K == 0:
            ans = [0, 0, 1, 1]
        else:
            ans = [-1]
    else:
        for i in range(max_val):
            if i != K:
                ans.append(i)
        ans.append(K)
        for i in range(max_val-1, -1, -1):
            if i != K:
                ans.append(i)
        ans.append(K)
else:
    ans = [-1]
print(*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()
if k >= 2**m:
    print(-1)
    exit()
if k == 0:
    for i in range(2**m):
        print(i,i,end = ' ')
    exit()
res = []
used = [True]*(2**m)

tank = []

for i in range(2**m):
    if used[i]:
        tank.append((i,i^k))
        used[i] = used[i^k] = False
for i in range(len(tank)):
    if i % 2 == 1:
        continue
    a = tank[i][0]
    b = tank[i][1]
    c = tank[i+1][0]
    d = tank[i+1][1]
    res += [c,a,b,c,d,b,a,d]

for e in res:
    print(e,end=' ')

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:
  ans = list(range(2**M))
  del ans[K]
  rev = list(reversed(ans))
  ans.append(K)
  ans.extend(rev)
  ans.append(K)
  print(' '.join(map(str, ans)))

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

Solution (Python):
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

M,K = inpl()
MAX = 2**M

if M != 1 and MAX > K:
    ans = []
    for i in range(MAX):
        if i != K:
            ans.append(i)
    ans.append(K)
    for i in reversed(range(MAX)):
        if i != K:
            ans.append(i)
    ans.append(K)
    print(' '.join(map(str,ans)))
elif M == 1:
    if K == 0:
        print('0 0 1 1')
    else:
        print(-1)
else:
    print(-1)

Solution (Python):


from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy
from collections import defaultdict


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    if y > x // 2:
        y = x - y

    ret = 1

    for i in range(0, y):
        j = x - i
        i = i + 1

        ret = ret * j
        ret = ret // i

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


class UnionFind:

    def __init__(self, n):
        self.parent = [i for i in range(n)]

    def root(self, i):
        if (self.parent[i] == i):
            return i
        self.parent[i] = self.root(self.parent[i])
        return self.parent[i]

    def unite(self, i, j):
        rooti = self.root(i)
        rootj = self.root(j)
        if rooti == rootj:
            return
        if i < j:
            self.parent[rootj] = rooti
        else:
            self.parent[rooti] = rootj

    def same(self, i, j):
        return self.root(i) == self.root(j)





def main():
    m, k = intin()

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

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

    mm = 2**m

    if k >= mm:
        print('-1')
        return

    output = []

    for i in range(mm):
        if i != k:
            output.append(str(i))

    output.append(str(k))

    for i in range(mm - 1, -1, -1):
        if i != k:
            output.append(str(i))

    output.append(str(k))

    print(' '.join(output))


if __name__ == '__main__':
    main()

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

if K == 0:
  print("0 0",end = "")
  for i in range(1, pow(2, M)):
    print("", i, i, end = "")
  print()
  exit()

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

N = pow(2, M)
if K >= N:
  print(-1)
  exit()
 
if K == 1:
  k = 1
  a = 2
  b = 3
elif K % 2 == 1:
  k = K
  a = 1
  b = K - 1
else:
  k = K
  a = 1
  b = K + 1

print(a, k, end = " ")
for i in range(N):
  if i != a and i != b and i != k:
    print(i, end = " ")
print(a, b, end = " ")
for i in range(N - 1, -1, -1):
  if i != a and i != b and i != k:
    print(i, end = " ")
print(k, b)

Solution (Python):

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

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

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

Solution (Python):
import sys, math, collections, heapq, itertools
F = sys.stdin
def single_input(): return F.readline().strip("\n")
def line_input(): return F.readline().strip("\n").split()
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0: a, b = b, a % b
    return b
  
def solve():
    M, K = map(int, line_input())
    if K >= pow(2, M): print(-1)
    elif M == 0:
        if K == 0: print("0 0")
        else: print(-1)
    elif M == 1:
        if K == 0: print("0 0 1 1")
        else: print(-1)
    else:
        ans = []
        if K == 0: ans = [int(i)//2 for i in range(2 ** (M + 1))]
        else:
            ans.append(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(" ".join(map(str, ans)))
    return 0
  
if __name__ == "__main__":
    solve()

Solution (Python):
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq as hq
import itertools as its
import operator as op



inf = float('inf')
N = 0


def set_inputs():
    global N
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    
    M, K = get_li()
    if K >= 2 ** M:
        print(-1)
        return
    if M == 0 and K == 0:
        print(0, 0)
        return
    if M == 1:
        if K == 0:
            print(0, 0, 1, 1)
        else:
            print(-1)
        return
    q = deque()
    q.append(K)
    for i in range(2 ** M):
        if i == K:
            continue
        q.append(i)
        q.appendleft(i)
    q.append(K)
    print(' '.join(map(str, q)))
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


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


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types, sep=None):
    if len(types) == 1:
        return [types[0](input().strip()) for _ in range(n)]
    return list(zip(*(
        [t(x) for t, x in zip(types, input().strip().split(sep=sep))]
        for _ in range(n)
    )))


if __name__ == '__main__':
    main()

Solution (Python):
from collections import deque

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

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

if k == 0:
    q = deque([])
    for i in range(2 ** m):
        q.append(i)
        q.appendleft(i)
    print(*q)
    exit()

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

S = set(i for i in range(2 ** m))

q = deque([0, k])
S.remove(0)
S.remove(k)

for s in S:
    q.appendleft(s)
    q.append(s)

q.appendleft(0)
q.append(k)

print(*q)

Solution (Python):
'''input
5 12
'''

N, K = [int(x) for x in input().split()]

if not K:
	for i in range(1 << N):
		print(i, i, end=' ')
	exit()

if N == 1:
	if K == 1:
		print(-1)
		exit()

if K >= 1 << N:
	print(-1)
	exit()

prad = list(range(1 << N))

prad.remove(K)

pab = list(reversed(prad))


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

print(K, end=' ')
for i in pab:
	print(i, end=' ')
print(K)

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

Solution (Python):
print(' '.join(list(map(str,((lambda n:[["-1"],["0 0 1 1"]][not n[1]]if n[0]==1 else([n[1]]+list(range(n[1]))+list(range(n[1]+1,(1<<n[0])))+[n[1]]+list(range((1<<n[0])-1,n[1],-1))+list(range(n[1]-1,-1,-1))if n[1]<(1<<n[0])else["-1"]))(list(map(int,input().split()))))))))