Given two integers $n$ and $x$, construct an array that satisfies the following conditions:   for any element $a_i$ in the array, $1 \le a_i<2^n$;  there is no non-empty subsegment with bitwise XOR equal to $0$ or $x$,  its length $l$ should be maximized. 

A sequence $b$ is a subsegment of a sequence $a$ if $b$ can be obtained from $a$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.


-----Input-----

The only line contains two integers $n$ and $x$ ($1 \le n \le 18$, $1 \le x<2^{18}$).


-----Output-----

The first line should contain the length of the array $l$.

If $l$ is positive, the second line should contain $l$ space-separated integers $a_1$, $a_2$, $\dots$, $a_l$ ($1 \le a_i < 2^n$) — the elements of the array $a$.

If there are multiple solutions, print any of them.


-----Examples-----
Input
3 5

Output
3
6 1 3
Input
2 4

Output
3
1 3 1 
Input
1 1

Output
0



-----Note-----

In the first example, the bitwise XOR of the subsegments are $\{6,7,4,1,2,3\}$.

Difficulty: interview

Starter code:

Solutions:
n, x = list(map(int, input().split()))
a = []
lst = 0
for i in range(1, 1 << n):
  if i ^ x > i:
    a.append(i ^ lst)
    lst = i
print(len(a))
print(' '.join(str(i) for i in a))


import sys
input = sys.stdin.readline

n,x=list(map(int,input().split()))

if n==x==1:
    print(0)
    return


ANS=[]
for i in range(n):
    if i+1==(x).bit_length():
        continue
    ANS=ANS+[(1<<i)]+ANS

print(len(ANS))
print(*ANS)


N, X = list(map(int, input().split()))
if X == 0 or X >= 2**N:
    A = [a for a in range(N)]
else:
    for i in range(N):
        if (1<<i) & X:
            A = [a for a in range(N) if a != i]
            break
    
def calc(B):
    if B:
        b = B[-1]
        t = calc(B[:-1])
        return t + [1<<b] + t
    return []

ca = calc(A)
print(len(ca))
if len(ca):
    print(*ca)



def main():
    buf = input()
    buflist = buf.split()
    n = int(buflist[0])
    x = int(buflist[1])
    npow2 = int(2 ** n)
    if n == 1:
        if x == 1:
            print(0)
        else:
            print(1)
            print(1)
        return
    mask = x
    if x >= npow2:
        mask = 0
    available = set()
    for i in range(1, npow2):
        if i != x:
            available.add(i)
    a = []
    while available:
        new_elem = available.pop()
        new_elem = new_elem ^ mask
        a.append(new_elem)
        if x < npow2:
            elem_to_remove = new_elem ^ x
            available.remove(elem_to_remove ^ mask)
        mask = mask ^ new_elem
    print(len(a))
    print(' '.join(list(map(str, a))))

def __starting_point():
    main()

__starting_point()

n, x = map(int, input().split())    
res = []
s = {x}
prev = 0
for i in range(1, 1 << n):
    curr = prev ^ i
    if curr in s: continue
    res.append(curr)
    prev = i
    s.add(x ^ i)
print(len(res))
print(*res)

#Bhargey Mehta (Sophomore)
#DA-IICT, Gandhinagar
import sys, math, queue, bisect
#sys.stdin = open("input.txt", "r")
MOD = 10**9+7
sys.setrecursionlimit(1000000)

n, x = map(int, input().split())
taken = {0, x}
b = [0]
for i in range(1, 1<<n):
    if i not in taken and i^x not in taken:
        b.append(i)
        taken.add(i)

b = [b[i]^b[i-1] for i in range(1, len(b))]
print(len(b))
print(*b)

n,x=map(int,input().split())
if x>=2**n:
    print(2**n-1)
    print(*([1]+[i^(i+1) for i in range(1,2**n-1)]))
else:
    print(2**(n-1)-1)
    if n==1:
        return
    a=[]
    bad=[0]*(2**n)
    bad[0],bad[x]=1,1
    for i in range(2**n):
        if bad[i]==0:
            a.append(i)
            bad[i]=1
            bad[i^x]=1
    print(*([a[0]]+[a[i]^a[i+1] for i in range(len(a)-1)]))

n, x = list(map(int, input().split()))
nn = 2 ** n
if x >= nn:
    x = 0

ans = []

for i in range(n):
    oks = [True] * nn
    oks[x] = False
    cur = 0
    for j in ans[::-1]:
        cur ^= j
        oks[cur] = False
        oks[cur ^ x] = False
    try:
        a = next(j for j, ok in enumerate(oks[1:], 1) if ok)
    except StopIteration:
        break
    ans = [*ans, a, *ans]

print(len(ans))
if ans:
    print(' '.join(map(str, ans)))


def gns():
    return [int(x) for x in input().split()]
n,x=gns()

# if len(str(x))>n:
#     n+=1
if n==1:
    if x==1:
        print(0)
        quit()
    print(1)
    print(1)
    quit()
b=len(bin(x))-2
if x!=1:
    ans=[1]
else:
    ans=[2]
cur=1
for i in range(n-2):
    if cur==b-1:
        cur+=1
    ans=ans+[1<<cur]+ans
    cur+=1
if x>=(1<<n):
    ans=ans+[1<<cur]+ans
# y=((1<<n)-1)^x
y=x
# if x<(1<<n) and (x+1)!=(1<<n):
#     ans=[c^y for c in ans]
print(len(ans))
print(' '.join(map(str,ans)))


n, x = map(int, input().split())

ans = []


last = 0
for i in range(1, 2 ** n) : 
    if ((i ^ x) > i) :
        ans.append(last ^ i)
        last = i

print(len(ans))
for i in ans :
    print(i, end = " ")


#
n, x  = list(map(int, input().split()))

def creat(n, x):
    if x > 2**n:
        arr = [i for i in range(1, 2**n)]
        return arr
        
    used  = {i:False for i in range(1, 2**n)}
    arr   = []

    for i in range(1, 2**n):
        if i == x:continue
        if used[i] == True: continue
        used[i]    = True    
        used[i^x]  = True
        arr.append(i)
    
    return arr

a  = creat(n, x)
if len(a) == 0:
    print(0)
else:    
    a_ = [a[0]] 
    a_.extend([u ^ v for u, v in zip(a[1:], a[:-1])])

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



N, X = map(int, input().split())

ex = [False] * 2 ** 18
ex[0] = True
ans = [0]

for i in range(1, 2 ** N):
    if ex[i ^ X]:
        continue
    else:
        ans.append(i)
        ex[i] = True

print(len(ans) - 1)
for i in range(1, len(ans)):
    print(ans[i] ^ ans[i-1], end=" ")


n, x = [int(x) for x in input().split()]
ans = []
vis = [0] * ((2 ** 18) + 1)
lmt = 2 ** n
xor = 0
vis[0], vis[x] = 1, 1
for i in range(1, lmt):
    if vis[i]:
        continue
    ans.append(xor ^ i)
    xor = i
    vis[i] = 1
    vis[i ^ x] = 1
print(len(ans))
print(*ans)
    


n,x=list(map(int,input().split()))
n=1<<n
ans=(n>>(x<n))-1
print(ans)
q,t=0,0
a=[0]*n
for i in range(1,n):
    if i<(i^x):
        a[t]=i^q
        q,t=i,t+1
print(*a[:t])


n,x=map(int,input().split())
n=1<<n
ans=(n>>(x<n))-1
print(ans)
q,t=0,0
a=[0]*n
for i in range(1,n):
    if i<(i^x):
        a[t]=i^q
        q,t=i,t+1
print(*a[:t])

v=[0]
n,x=map(int,input().split())
e=[0]*(1<<18)
e[0]=1
for i in range(1,1<<n):
    if e[x^i]==1:continue
    e[i]=1
    v.append(i)
print(len(v)-1)
print(*[v[i]^v[i-1] for i in range(1,len(v))])

n, x = map(int, input().split())

ans = [0]

for i in range(1, 2 ** n) : 
    if ((i ^ x) > i) :
        ans.append(i)

print(len(ans) - 1)
for i in range(1, len(ans)) :
    print(ans[i] ^ ans[i - 1], end = " ")

n, x = map(int, input().split())
if x>=2**n:
    prefix_array = []
    for i in range(1, 2**n):
        prefix_array.append(i)
else:
    prefix_array = []
    compl = {}
    for i in range(1, 2**n):
        if i==x: continue
        try:
            if compl[i]: pass
        except:
            prefix_array.append(i)
            compl[i^x] = True
if prefix_array==[]: print(0)
else:
    res = [prefix_array[0]]
    for i in range(len(prefix_array)-1):
        res.append(prefix_array[i]^prefix_array[i+1])
    print(len(res))
    for i in res: print(i, end=' ')
    print()


n,x = map(int,input().split())
mark = [0 for x in range(1<<18 +1)]
mark[x] = 1
curent =0
maxA = 1<<n
ans = []
for i in range(1,maxA):
    if i!=x:
        result = i^x
        if mark[i]==0:
            ans.append(i^curent)
            mark[result]=1
            mark[i]=1
            curent=i
        elif mark[result]==0 and result<maxA:
            ans.append(curent^result)
            mark[result]=1
            curent=result
print(len(ans))
print(*ans)

n , x = list(map(int,input().split()))
mark = [0 for x in range(1 << 18 +1)]
mark[x] = 1
cur = 0
MAXN = 1 << n
ans = []
for i in range(1 , MAXN):
    if i != x:
        res = i ^ x
        if mark[i] == 0:
            ans.append(i^cur)
            mark[res] = 1
            mark[i] = 1
            cur = i
print(len(ans))
print(*ans)


n, x = list(map(int, input().split()))

k, b = 1 << n, []
if x >= k:
    print(k - 1)
    b = list(range(1, k))
else:
    print((k - 2) >> 1)
    _b, b = set(range(1, k)), set()
    for bi in _b:
        b.add(bi)
        if x ^ bi in b:
            b.remove(x ^ bi)
    if x in b:
        b.remove(x)

if b:
    b = list(b)
    a = [b[0]] + [b[i] ^ b[i + 1] for i in range(len(b) - 1)]
    print(*a)


def main():
	n, x = list(map(int, input().split()))
	f = []
	n = 1 << n
	cx = [0 for _ in range(n + 299)]
	for i in range(n):
		if Find_x(int(x ^ i), f) == False: 
			f.append(i)
	##print (f)
	print(len(f) - 1)
	for i in range(len(f) - 1):
		print(f[i] ^ f[i + 1], end = ' ')

def Find_x(x, a):
	l = 0
	r = len(a) - 1
	while l <= r:
		m = int((l + r) / 2)
		if a[m] == x: return True
		if a[m] > x: r = m - 1
		else : l = m + 1
	return False

def __starting_point():
	main()
__starting_point()

n, x = list(map(int ,input().split()))
a = []; d = {0:True}; d1=[0]
if (x<(1<<n)):

    

    for t in range(1, 1<<n):
        
        if not d.get(t^x, False):
            a.append(t^d1[-1])
            d[t] = True
            d1.append(t)
    print(len(a))
    print(" ".join(map(str,a)))
else:
    for t in range(1, (1<<n)):
        
        
        a.append(t^(t-1))  
    print(len(a))
    print(" ".join(map(str,a)))
      


n,x=map(int,input().split())
markings=[0 for i in range(2**n-1)]
for i in range(1,2**n):
    #print(i,markings)
    if markings[i-1]==0 and (x^i)<(2**n) and i!=x:
        markings[(x^i)-1]=1 
if x<2**n:
    markings[x-1]=1
arr=[]
for i in range(2**n-1):
    if markings[i]==0:
        arr.append(i+1)
print(len(arr))
if len(arr)>0:
    print(arr[0],end=" ")
    for i in range(1,len(arr)):
        print(arr[i]^arr[i-1],end=" ")
    print("")
        


from sys import stdin
# stdin=open('input.txt')

def input():
	return stdin.readline().strip()


# from sys import stdout
# stdout=open('input.txt',mode='w+')

# def print1(x, end='\n'):
# 	stdout.write(str(x) +end)


# a, b = map(int, input().split())

# l = list(map(int, input().split()))


# CODE BEGINS HERE.................

import math

n, x = list(map(int, input().split()))

seen = [False] * (2**(18))
seen[0] = True
seen[x] = True

a = []
pref_sum = 0
for i in range(2**n):
	if seen[i]:
		continue
	a.append(pref_sum ^ i)
	pref_sum = i
	seen[i] = True
	seen[x^i] = True
print(len(a))
print(*a)

# CODE ENDS HERE....................
# stdout.close()