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
from typing import Any, Callable, Deque, Dict, List, Mapping, Optional, Sequence, Set, Tuple, TypeVar, Union






















from itertools import product, permutations  







def main():
    mod = 1000000007                
    inf = float('inf')              
    
    sys.setrecursionlimit(10**6)    
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def isp():   return input().split()
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    

    m, k = mi()
    
    if k >= 2 ** m:
        print(-1)
    elif m == 1:
        if k == 0:
            print('0 0 1 1')
        else:
            print(-1)
    else:
        left = [i for i in range(2**m) if i != k]
        L = left + [k] + list(reversed(left)) + [k]
        print(*L)



if __name__ == "__main__":
    main()

Solution (Python):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


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 1 1 0"
else:
    ans = list(range(2**m)) 
    ans1 = ans[:k] + ans[k+1:] + [k]
    ans2 = [k] + ans[:k] + ans[k+1:]
    ans = ans1 + ans2[::-1]
    ans = " ".join(map(str, ans))
print(ans)

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

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

def main():
    mod=10**9+7
    M,K=MI()
    N=pow(2,M)
    
    if K>=N or (M==1 and K==1):
        print(-1)
    elif M==1 and K==0:
        print(0,0,1,1)
    else:
        from collections import deque
        dq=deque()
        dq.append(K)
        for i in range(N):
            if i!=K:
                dq.append(i)
                dq.appendleft(i)
        dq.append(K)
        
        ans=[]
        while len(dq)!=0:
            ans.append(dq.pop())
        print(' '.join(map(str, ans)))
    

                

main()

Solution (Python):
def main():
    M, K = list(map(int, input().split(' ')))
    if K >= 2 ** M:
        print(-1)
        return
    if M == 0:
        print('0 0')
        return
    if M == 1:
        if K == 0:
            print('0 0 1 1')
        else:
            print(-1)
        return
    
    arr = list(map(str, [i for i in range(2 ** M) if i != K]))
    rev_arr = arr.copy()
    rev_arr.reverse()
    ans = arr + [str(K)] + rev_arr + [str(K)]
    print(' '.join(ans))


if __name__ == '__main__':
    main()

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

Solution (Python):
m,k = 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:
    print(-1)
    exit()
if k > 2**m - 1:
    print(-1)
    exit()

ans=[]

for i in range(2**m):
    if i!=k:
        ans.append(i)
ans.append(0)
ans.append(k)
for i in reversed(range(1,2**m)):
    if i!=k:
        ans.append(i)
ans.append(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 k >= 2 ** m:
        print(-1)
        exit()

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

    ans = [k] + res + [k] + res[::-1]
    print(*ans)

Solution (Python):
m,k = map(int,input().split())
if m == 1:
    if k == 0:
        print(0,0,1,1)
    else:
        print(-1)
elif 2**m <= k:
    print(-1)
else:
    remain = set(range(2**m))
    use = set()
    count = 0
    while k:
        if k & 1:
            remain.remove(2**count)
            use.add(2**count)
        k >>= 1
        count += 1
    ans = []
    remain = list(remain)
    use = list(use)
    for i in remain:
        ans.append(str(i))
    for i in use:
        ans.append(str(i))
    for i in remain[::-1]:
        ans.append(str(i))
    for i in use[::-1]:
        ans.append(str(i))
    print(" ".join(ans))

Solution (Python):
import sys

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

if M == 1:
    if K == 0:
        print("0 0 1 1")
    else:
        print(-1)
else:
    if K >= 2**M:
        print(-1)
    else:
        a = [i for i in range(2**M) if i != K]
        b = sorted(a, reverse=True)
        print(" ".join(list(map(str, a + [K] + b + [K]))))

Solution (Python):
from itertools import chain
m,k=map(int,input().split())
if 0<k<2**m and m>=2:
    print(*[str(i) for i in chain(range(0,k),range(k+1,2**m),[k],range(2**m-1,k,-1),range(k-1,-1,-1),[k])])
elif k==0:
    print(*[str(i) for i in chain(range(0,2**m),range(2**m-1,-1,-1))])
else:
    print(-1)

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

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

Solution (Python):
m,k=map(int,input().split())
x=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):
from itertools import chain
m,k=map(int,input().split())
if k==0:
    print(" ".join([str(i) for i in chain(range(0,2**m),range(2**m-1,-1,-1))]))
elif 0<k<2**m:
    s=0
    for i in range(0,2**m):
        if i!=k:
            s^=i
    if s==k:
        print(" ".join([str(i) for i in chain(range(0,k),range(k+1,2**m),[k],range(2**m-1,k,-1),range(k-1,-1,-1),[k])]))
    else:
        print(-1)
else:
    print(-1)

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

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

if m == 1:
    if k == 0:
        print("0 0 1 1")
    else:
        print(-1)
else:
    if 2**m <= k:
        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(*ANS)

Solution (Python):

import sys


buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


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


def read_float():
    return float(buff_readline())


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


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


def read_str_n():
    return readline().strip().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 K >= 2**(M+1):
        return [-1]

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

    p = []
    done = set()
    for a in range(2**M):
        if a in done:
            continue
        b = K ^ a
        if b >= 2**M:
            return [-1]
        p.append((a, b))
        done.add(a)
        done.add(b)

    if len(p) % 2 != 0:
        return [-1]

    ans = []
    for i in range(0, len(p), 2):
        a, b = p[i]
        c, d = p[i+1]
        ans.append(a)
        ans.append(b)
        ans.append(c)
        ans.append(d)
        ans.append(b)
        ans.append(a)
        ans.append(d)
        ans.append(c)

    return ans



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


if __name__ == '__main__':
    main()

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

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

        ans = l + [k] + l[::-1] + [k]

        ans2 = ''
        for a in ans:
            ans2 += str(a) + ' '
        print(ans2[:-1])
    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')
    elif k >= 1:
        print('-1')
else:
    if k < 2 ** m:
        l = list(range(2 ** m))
        l.pop(k)
        ans = l + [k] + l[::-1] + [k]
        print(' '.join(map(str, 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:
        L = [i for i in range(2 ** m) if i != k]
        ans = L + [k] + L[::-1] + [k]
        print(*ans, sep=' ')

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    

    
    

    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:
            res = []
            for i in range(2**m):
                if i != 0 and i != k:
                    res.append(i)
            if k == 0:
                res = res + [0] + res[::-1] + [0]
            else:
                res = res + [0, k] + res[::-1] + [k, 0]
            print(*res)

if __name__ == '__main__':
    main()

Solution (Python):


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


M, K = LI()


def solve():
    n = 2 ** M
    l = [i for i in range(n) if i != K]
    ret = l + [K] + l[::-1] + [K]
    return ret


def main():
    if K >= 2 ** M:
        ans = [-1]
    elif M == 1:
        if K == 0:
            ans = [0, 0, 1, 1]
        else:
            ans = [-1]
    else:
        ans = solve()

    print(*ans)


if __name__ == "__main__":
    main()

Solution (Python):
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
import numpy as np
INF = float("inf")











M,K = map(int,input().split())
if M == 1:
    if K == 0:
        ans = [0,0,1,1]
        print(*ans)
    else:
        print(-1)
else:
    if K > 2**M - 1 :
        print(-1)
    else:
        if K == 0:
            ans = []
            for i in range(2**M):
                ans.append(i)
                ans.append(i)
            print(*ans)
        else:
            ans = deque([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


def solve(M: int, K: int):
    if K >= (1 << M):
        print(-1)
        return
    if M == 1:
        if K == 0:
            print(0, 0, 1, 1)
        else:
            print(-1)
        return
    for i in range(1 << M):
        if i != K:
            print(i, end=" ")
    print(K, end=" ")
    for i in reversed(range(1 << M)):
        if i != K:
            print(i, end=" ")
    print(K)


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):
m,k = map(int,input().split())
if m*k == 1:
  print(-1)
  exit()
  
if k == 0:
  ans = []
  for i in range(2**m):
    ans.append(i)
    ans.append(i)
  print(*ans)
  exit()
  
if 2**m <= k:
  print(-1)
else:
  ans = [k]
  chk = list(range(2**m))
  chk.remove(k)
  ans = ans+chk+[k]+chk[::-1]
  print(' '.join(map(str,ans)))

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

Solution (Python):

import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    M,K=map(int,input().split())
    if K>2**M-1:
        print(-1)
    elif M==1:
        if K==0:
            print(0,0,1,1)
        else:
            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(*ans)

if __name__ == '__main__':
    main()

Solution (Python):
import sys
M, K = map(int,input().split())
if M == 0:
    if K == 0:
        print(*[0, 0])
    else:
        print(-1)
    sys.exit()

if M == 1:
    if K == 0:
        print(*[0, 1, 1, 0])
    else:
        print(-1)
    sys.exit()

N = 2 ** M

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

ans = []

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

ans.append(K)

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

ans.append(K)

print(*ans)

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

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

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

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

left = [i for i in range(2**M) if not i == K]

ans = left + [K] + left[::-1] + [K]

print(*ans)

Solution (Python):
import sys
import time

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    m, k = list(map(int, readline().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:
            x = [i for i in range(2 ** m)]
            x.remove(k)
            y = x[::-1]
            ans = x + [k] + y + [k]
            print(*ans)
        else:
            print(-1)


if __name__ == '__main__':
    main()

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

def main():
    M, K =map(int, input().split())
    k = bin(K)[2:]

    """
    構成問題無理です。。。。。。
    K < 2^Mを最初にちゃんと定式化しておけば、Mに関して場合分けしたくなるのか？
    （Kで場合分けして詰んだ人）

    そしてどっちみちM=2で実験しても定式化できんかった。。。。。。
    「K以外の0以上2M未満の整数を昇順に並べた数列をbとします。またbの逆順をcとします。
    このとき bKcK と並べてできる数列をaとすればよいです。」
    →言われれば納得するけどなあ

    0 ¥oplus 1 ¥oplus ... ¥oplus (2^M-1) = 0　(M >= 2)なのは覚えても良さそう。
    """

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

    b = [i for i in range(K)] + [i for i in range(K + 1, 2 ** M)]
    c = list(reversed(b))
    ans = b + [K] + c + [K]
    print(" ".join(map(str, ans)))


if __name__ == "__main__":
    main()

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

Solution (Python):
def main():
    M, K = map(int, input().split())
    if K >= 2 ** M:
        print(-1)
        exit()
    
    if K == 1 and M == 1:
        print(-1)
        exit()
    
    if M == 0 and K >= 1:
        print(-1)
        exit()
    
    if M == 0:
        print(0,0)
        exit()
    
    if K == 0 and M == 1:
        print(0,0,1,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)

    


if __name__ == "__main__":
    main()

Solution (Python):
m,k=map(int,input().split())
if k>2**m-1:
    print(-1)
elif m==1 and k==1:
    print(-1)
else:
    a,b=0,0
    i=0
    while k>0:
        if k%2:
            a+=2**i
        k//=2
        i+=1
    
    if a==0:
        ans=[]
        for i in range(2**m):
            ans.append(i)
            ans.append(i)
    else:
        ans=[0]*2**(m+1)
        ans[2**m-1]=b
        ans[-1]=a
        ans[2**m]=a
        ans[0]=b
        s={a,b}
        idx=0
        
        for i in range(2**m):
            if i not in s:
                ans[idx+1]=i
                ans[-2-idx]=i
                idx+=1
    print(*ans)

Solution (Python):
def test(m):
    t = [i for i in range(2**m)]
    for i in range(2**m):
        t.append(i)
    t.sort()
    st = set()
    bt = set()
    from itertools import permutations
    for v in permutations(t):
        taget = v[0]
        x = 0
        idx = 1
        while idx < len(v) and v[idx] != taget:
            x = x ^ v[idx]
            idx += 1
        if x in st or x in bt:
            continue
        f = True
        for i in range(1, len(v)):
            g = False
            y = 0
            idx = i+1
            while idx < len(v):
                if v[i] == v[idx]:
                    g = True
                    break
                y = y ^ v[idx]
                idx += 1
            if g:
                if y != x:
                    f = False
                    break
        if f:
            st.add(x)
            print(x, v)

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

    x = 0
    for i in range(2**m):
        if i == k:
            continue
        x ^= i
    if k == 0:
        for i in range(2**m):
            print(i, i, end=" ")
    elif x == k:
        for i in range(2**m):
            if i == k:
                continue
            print(i, end=" ")
        print(k, end=" ")
        for i in reversed(range(2**m)):
            if i == k:
                continue
            print(i, end=" ")
        print(k)
    else:
        print(-1)

if __name__ == "__main__":
    main()

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

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

Solution (Python):
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product

def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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

if m==0 and k!=0:
    print(-1)
    quit()
elif m==1 and k!=0:
    print(-1)
    quit()
elif k>=2**m:
    print(-1)
    quit()
if m==1 and k==0:
    print(*[0,0,1,1])
    quit()

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

anslst=lst[:]+[k]+sorted(lst,key=lambda x: -x)+[k]
print(*anslst)

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

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

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

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 = [i for i in range(2**m) if i != k]
    ans = [k] + a + [k] + a[::-1]
    print(*ans)

Solution (Python):

from collections import deque

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


if k>=pow(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:
    ans = deque()
    ans.append(k)
    for i in range(pow(2,m)):
        if i!=k:
            ans.append(i)
            ans.appendleft(i)
    ans.append(k)
    print(' '.join(map(str, ans)))

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

if K>=2**M:
    print(-1)
    sys.exit()
    
if M==1:
    if K==0:
        print(*[0,0,1,1])
        sys.exit()
    else:
        print(-1)
        sys.exit()
L=[]
l=[int(i) for i in range(2**M) if i !=K]
L.extend(l)
L.append(K)
L.extend(l[::-1])
L.append(K)

print(*L)

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

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

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

Solution (Python):
m, k = map(int, input().split())
if 2**m <= k:
    print(-1)
    exit()
elif m == 0 and k == 0:
    print("0 0")
    exit()
elif m == 1 and k == 1:
    print(-1)
    exit()
elif m == 1 and k == 0:
    print("1 1 0 0")
    exit()
l = [i for i in range(2**m) if i != k]
rev_l = sorted(l, reverse=True)
ans = l + [k] + rev_l + [k]
print(" ".join(map(str, ans)))

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

if M < 2:
    if K != 0:
        print(-1)
    else:
        anss = []
        for A in range(2**M):
            anss += [A, A]
        print(' '.join(map(str, anss)))
else:
    if K > 2**M - 1:
        print(-1)
    else:
        anss = []
        for A in range(2**M):
            if A == K: continue
            anss.append(A)
        anss = anss + [K] + anss[::-1] + [K]
        print(' '.join(map(str, anss)))

Solution (Python):

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

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

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    M, K = map(int, rl().split())
    
    if M == 1:
        if 1 <= K:
            print(-1)
        else:
            print(0, 0, 1, 1)
        exit()
    
    if 1 << M <= K:
        print(-1)
        exit()
    
    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)))


if __name__ == '__main__':
    solve()

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

if M <= 1:
    if K > 0:
        print(-1)
        exit()
    else:
        if M == 1:
            print(" ".join(["0", "0" , "1", "1"]))
            exit()
        else:
            print("0 0")
            exit()
elif K >= 2 ** M:
        print(-1)
        exit()
ans = [str(K)]
exclude_k = [str(i) for i in range(2 ** M) if i != K]
ans.extend(exclude_k)
ans.append(str(K))
ans.extend(exclude_k[::-1])
print(" ".join(ans))

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

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

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)
  else:print(-1)
  exit()
a=[i for i in range(2**m) if i!=k]
ans=[k]+a+[k]+a[::-1]
print(*ans)

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

if m == 1:
    if k == 0:
        ans = [0, 0, 1, 1]
    else:
        ans = []

elif k < 2 ** m:
    li = list(range(2 ** m))
    li.remove(k)
    ans = li + [k] + li[::-1] + [k]

else:
    ans = []

if ans:
    print(*ans)
else:
    print(-1)

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

if m == 0:
    if k == 0:
        ans = [0, 0]
    else:
        ans = []

elif m == 1:
    if k == 0:
        ans = [0, 0, 1, 1]
    else:
        ans = []

elif k < 2 ** m:
    li = list(range(2 ** m))
    li.remove(k)
    ans = li + [k] + li[::-1] + [k]

else:
    ans = []

if ans:
    print(*ans)
else:
    print(-1)

Solution (Python):
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): 
  return list(map(int,input().split()))
def m(): 
  return map(int,input().split())
def onem(): 
  return int(input())
def s(x): 
  a = []
  if len(x) == 0:
    return []
  aa = x[0]
  su = 1
  for i in range(len(x)-1):
    if aa != x[i+1]:
      a.append([aa,su])
      aa = x[i+1]
      su = 1
    else:
      su += 1
  a.append([aa,su])
  return a
def jo(x): 
  return " ".join(map(str,x))
def max2(x): 
  return max(map(max,x))
def In(x,a): 
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
  ll = 0
  rr = r
  while True:
    mid = (ll+rr)//2

  if rr == mid:
    return ll
  if (ここに評価入れる):
    rr = mid
  else:
    ll = mid+1
"""

n,k = m()

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 2<<(n-1) > k:
    po = []

    op = []

    for i in range((2<<(n-1))):
      if i == k:
        continue
      else:
        if po == "":
          po.append(i)
          op.append(i)
        else:
          po.append(i)
          op.append(i)
    op.reverse()
    print("{0} {1} {2} {3}".format(jo(po),k,jo(op),k))
  else:
    print(-1)

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

Solution (Python):

import sys

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

M, K = lr()
if K >= 2 ** M:
    print(-1); exit()
if M == 1:
    if K == 0:
        print("0 0 1 1")
    else:
        print(-1)
    exit()
A = [x for x in range(2 ** M) if x != K]
answer = A + [K] + A[::-1] + [K]
print(*answer)

Solution (Python):
m, k = [int(x) for x in input().split()]
if m == 1:
    if k == 0:
        print(0, 0, 1, 1)
    else:
        print(-1)
else:
    if k < 1 << m:
        a = [str(i) for i in range(1 << m) if i != k]
        print(' '.join(a), k, ' '.join(reversed(a)), k)
    else:
        print(-1)

Solution (Python):
MOD = 10 ** 9 + 7
INF = 10 ** 10
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)

def main():
    m,k = map(int,input().split())
    if k >= pow(2,m):
        print(-1)
        return
    if m == 1:
        if k == 1:
            print(-1)
        else:
            print('{0} {0} {1} {1}'.format(0,1))
        return
    
    ans = [k]
    ans2 = [k]
    lim = pow(2,m)
    for i in range(lim):
        if i != k:
            ans.append(i)
        if lim - i - 1 != k:
            ans2.append(lim - i - 1)
    ans += ans2
    print(*ans)  

if __name__ =='__main__':
    main()