Problem:
 Score : 400 points    Problem Statement In some other world, today is Christmas.  Mr. Takaha decides to make a multi-dimensional burger in his party. A level- L burger ( L is an integer greater than or equal to 0 ) is the following thing:   A level- 0 burger is a patty.  A level- L burger (L \geq 1) is a bun, a level- (L-1) burger, a patty, another level- (L-1) burger and another bun, stacked vertically in this order from the bottom.   For example, a level- 1 burger and a level- 2 burger look like BPPPB and BBPPPBPBPPPBB (rotated 90 degrees), where B and P stands for a bun and a patty.  The burger Mr. Takaha will make is a level- N burger. Lunlun the Dachshund will eat X layers from the bottom of this burger (a layer is a patty or a bun). How many patties will she eat?      Constraints  1 \leq N \leq 50  1 \leq X \leq ( the total number of layers in a level- N burger )  N and X are integers.         Input Input is given from Standard Input in the following format:  N  X       Output Print the number of patties in the bottom-most X layers from the bottom of a level- N burger.        Sample Input 1 2 7      Sample Output 1 4  There are 4 patties in the bottom-most 7 layers of a level- 2 burger ( BBPPPBPBPPPBB ).       Sample Input 2 1 1      Sample Output 2 0  The bottom-most layer of a level- 1 burger is a bun.       Sample Input 3 50 4321098765432109      Sample Output 3 2160549382716056  A level- 50 burger is rather thick, to the extent that the number of its layers does not fit into a 32 -bit integer.

Solution (Python):
def main():
	n, x = map(int, input().split())
	a, p = [1], [1]
	for i in range(n):
		a.append(a[i]*2 + 3)
		p.append(p[i]*2 + 1)

	def f(n, x):
		if n == 0:
			return 0 if x <= 0 else 1
		elif x <= 1+a[n-1]:
			return f(n-1, x-1)
		else:
			return p[n-1] + 1 + f(n-1, x-2-a[n-1])

	print(f(n, x))

if __name__ == '__main__':
    main()

Solution (Python):
N, X = map(int, input().split())
a = [2**(i+2) - 3 for i in range(N+1)]  
p = [2**(i+1) - 1 for i in range(N+1)]  
def f(N, X):
    if N == 0:
        return 1 if X > 0 else 0
    elif X <= 1 + a[N-1]:
        return f(N-1, X-1)
    else:
        return p[N-1] + 1 + f(N-1, X-2-a[N-1])
print(f(N, X))

Solution (Python):
nums = [0] * 51
ps = [0] * 51


def calc(l, x):
    global nums, ps

    if l == 0:
        if x == 0:
            return 0
        else:
            return 1

    if x == 1:
        return 0
    elif x <= 1 + nums[l - 1]:
        return calc(l - 1, x - 1)
    elif x == 2 + nums[l - 1]:
        return ps[l - 1] + 1
    elif x <= 2 + 2 * nums[l - 1]:
        return ps[l - 1] + 1 + calc(l - 1, x - 2 - nums[l - 1])
    else:
        return ps[l]


def main():
    global nums, ps
    nums[0] = 1
    ps[0] = 1
    for i in range(len(nums)):
        if i == 0:
            continue
        nums[i] = 2 * nums[i - 1] + 3
        ps[i] = 2 * ps[i - 1] + 1

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


if __name__ == "__main__":
    main()

Solution (Python):
N,X = map(int,input().split())
p=[0]*(N+1)
num=[0]*(N+1)
for i in range(N+1):
    p[i] = 2**(i+1)-1
for i in range(N+1):
    num[i] = 2**(i+2)-3
def f(L,x):
    if L == 0:
        return 0 if x<=0 else 1
    elif x < ((2**(L+2)-4)//2+1):
        return f(L-1,x-1)
    else:
        return p[L-1]+1+f(L-1,x-2-num[L-1])

print(f(N,X))

Solution (Python):
N, X = map(int, input().split())
maisuu = [1]
patimaisuu = [1]
for i in range(1,N + 1):
    maisuu.append(2 * maisuu[i - 1] + 3)
    patimaisuu.append(2 * patimaisuu[i - 1] + 1)

def pati(l, n):
    if n == 0:
        return 0
    elif l == 0:
        return 1
    elif n == 1:
        return 0
    elif 2 <= n <= maisuu[l] // 2:
        return pati(l - 1, n - 1)
    else:
        return pati(l - 1, n - maisuu[l - 1] - 2) + 1 + patimaisuu[l - 1]

print(pati(N, X))

Solution (Python):

import sys


def solve(N: int, X: int):
    total = [0] * (N + 1)
    p = [0] * (N + 1)
    total[0] = 1
    p[0] = 1
    for i in range(1, N + 1):
        total[i] = total[i - 1] * 2 + 3
        p[i] = p[i - 1] * 2 + 1
    def rec(idx, x):
        if x <= 0:
            return 0
        if x >= total[idx] - idx:
            return p[idx]
        elif x <= total[idx] // 2:
            return rec(idx - 1, x - 1)
        else:
            rest = x - (total[idx] // 2 + 1)
            ret = p[idx - 1] + 1 + rec(idx - 1, rest)
        return ret
    ret = rec(N, X)
    print(ret)
    return


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

if __name__ == '__main__':
    main()

Solution (Python):
def f(level,x):
    if level==0: return x

    if x in [1,0]:
        return 0
    elif x==b[level][0]:
        return b[level][1]
    elif 2<=x<b[level-1][0]+2:
        return f(level-1,x-1)
    elif x==b[level-1][0]+2:
        return b[level-1][1]+1
    elif b[level-1][0]+2<x<b[level][0]:
        return b[level-1][1]+1+f( level-1, x-(b[level-1][0]+2))

N,X=map(int,input().split())
b=[[1,1] for i in range(N+1)]
for i in range(1,N+1):
    b[i][0]=b[i-1][0]*2+3
    b[i][1]=b[i-1][1]*2+1

print(f(N,X))

Solution (Python):
N, X = map(int, input().split())
lenburger = [1]
lenputty = [1]
for i in range(N):
    lenburger.append(lenburger[i]*2+3)
    lenputty.append(lenputty[i]*2+1)
def burger(level, X):
    if level == 0:
        return 1
    elif X == 1:
        return 0
    elif X <= 1 + lenburger[level-1]:
        return burger(level-1, X-1)

    elif X == 2 + lenburger[level-1]:
        return 1 + lenputty[level-1]

    elif X <= 2 + lenburger[level-1]*2:
        return 1 + lenputty[level-1] + burger(level-1, X-2-lenburger[level-1])

    else:
        return lenputty[level]
print(burger(N, X))

Solution (Python):
sou = lambda n: 2 ** (n + 2) - 3
ptn = lambda n: 2 ** (n + 1) - 1


def pate(lv, x):
    if x == 0:
        return 0
    if x < 0:
        return -1
    else:
        for i in range(lv + 1):
            if x < lv - i + sou(i):
                i -= 1
                return ptn(i) + 1 + pate(i, x - (lv - i + sou(i) + 1))
        else:
            return ptn(lv)


lv, x = map(int, input().split())
print(pate(lv, x))

Solution (Python):
sou = lambda n: 2 ** (n + 2) - 3
ptn = lambda n: 2 ** (n + 1) - 1


def pate(lv, x):
    if x == 0:
        return 0
    if x < 0:
        return -1
    else:
        for i in range(lv + 1):
            if x < lv - i + sou(i):
                i -= 1
                re = ptn(i) + 1 + pate(i, x - (lv - i + sou(i) + 1))
                return re
        else:
            return ptn(lv)


lv, x = map(int, input().split())
print(pate(lv, x))

Solution (Python):
N,X = [int(i) for i in input().split()]
ans = 0
while N > 0:
    if X >= 2**(N+2) - 4: 
        ans += 2**(N+1) - 1
        break
    
    elif X > 2**(N+1) - 1: 
        ans += 2**N
        X -= 2**(N+1) - 1
        
    elif X == 2**(N+1) - 1: 
        ans += 2**N
        break
    
    elif X == 2**(N+1) - 2: 
        ans += 2**N - 1
        break
    
    elif X > 1:
        X -= 1
        
    else:
        break
    N -= 1
print(ans)

Solution (Python):
def count_p(x, n):
    y = 0
    i = n
    while(True):
        if i == 0:
            return 0
        xx = x - (n - i) + 3 - 2 ** (i + 1)
        if xx >= 0:
            y = 2 ** i - 1
            if xx > 0:
                y += count_p(xx - 1, i) + 1
            break
        else:
            i -= 1
    return y

n, x = map(int, input().split())
ans = count_p(x, n + 1)
print(ans)

Solution (Python):
n, x = map(int, input().split())

A = [1] * (n + 1)
P = [1] * (n + 1)
for i in range(1, n + 1):
    A[i] = A[i - 1] * 2 + 3
    P[i] = P[i - 1] * 2 + 1

c = 0
for i in list(range(n+1))[::-1]:
    if i == 0:
        c += 1

    elif x == 1:
        break

    elif x <= A[i - 1] + 1:
        x -= 1

    elif x == A[i - 1] + 2:
        c += P[i - 1] + 1
        break

    elif x <= A[i] - 1:
        c += P[i - 1] + 1
        x -= A[i - 1] + 2

    elif x == A[i]:
        c += P[i]
        break

print(c)

Solution (Python):
n, x = map(int, input().split())

A = [1] * (n + 1)
P = [1] * (n + 1)
for i in range(1, n + 1):
    A[i] = A[i - 1] * 2 + 3
    P[i] = P[i - 1] * 2 + 1


def pate(m, y):
    if m == 0:
        return 1
    else:
        c = 0

        if y >= 1:
            y -= 1

        if y >= 1:
            if y >= A[m - 1]:
                y -= A[m - 1]
                c += P[m - 1]
            else:
                c += pate(m - 1, y)
                y = 0

        if y >= 1:
            y -= 1
            c += 1

        if y >= 1:
            if y >= A[m - 1]:
                y -= A[m - 1]
                c += P[m - 1]
            else:
                c += pate(m - 1, y)
                y = 0

        if y >= 1:
            y -= 1

        return c


print(pate(n, x))

Solution (Python):
import numpy as np

n,x=map(int,input().split())
a,p=[1],[1]
for i in range(n):
	a.append(a[i]*2+3)
	p.append(p[i]*2+1)

def f(N,X):
	if N==0:
		return 0 if X<=0 else 1
	elif X <=1+a[N-1]:
		return f(N-1,X-1)
	else:
		return p[N-1]+1+f(N-1,X-2-a[N-1])
	
print (f(n,x))


def inputList():
	a=list(map(int,input().split()))
	return a

def multisort(li,index):
	return sorted(li,key=lambda x: x[index])

Solution (Python):
from sys import stdin
import numpy as np



N, X = [int(x) for x in stdin.readline().rstrip().split()]


def func(n, x):
  
  if x==0:
    return 0
  elif x==1 and n==0:
    return 1
  elif x==4*2**n-3:
    return 2*2**n-1
  elif x <= 4*2**(n-1)-3 +1:
    return func(n-1, x-1)
  else:
    return  func(n-1, 2*2**n-3) + func(n-1,x-2*2**n+1) +1
print(func(N, X))

Solution (Python):
from sys import stdin
import numpy as np



N, X = [int(x) for x in stdin.readline().rstrip().split()]


def func(n, x):
  
  if x==0:
    return 0
  elif x==1 and n==0:
    return 1
  elif x==4*2**n-3:
    return 2*2**n-1
  elif x <= 4*2**(n-1)-3 +1:
    return func(n-1, x-1)
  else:
    return  func(n-1, 2*2**n-3) + func(n-1,x-2*2**n+1) +1
print(func(N, X))

Solution (Python):
n,x = map(int,input().split())

a,p = [1],[1]
for i in range(n):
  a.append(a[i] * 2 + 3)
  p.append(p[i] * 2 + 1)
  
def f(n, x):
  if n == 0:
    if x <= 0: return 0
    else:return 1
  elif x <= 1 + a[n-1]:
    return f(n-1,x-1)
  else:
    return p[n-1] + 1 + f(n-1, x-2-a[n-1])

print(f(n,x))

Solution (Python):
N, X = map(int, input().split())
num_p = [2**(i+1)-1 for i in range(N+1)]
num_layer = [2**(i+2)-3 for i in range(N+1)]
def f(N, X):
    if N == 0:
        if X == 0:
            return 0
        else:
            return 1
    elif X == 1:
        return 0
    elif X <= 1 + num_layer[N-1]:
        return f(N-1, X-1)
    elif X == 2 + num_layer[N-1]:
        return 1 + num_p[N-1]
    elif X < 2 + 2 * num_layer[N-1]:
        return num_p[N-1] + 1 + f(N-1, X - 2 - num_layer[N-1])
    else:
        return 2 * num_p[N-1] + 1
print(f(N, X))

Solution (Python):
N, X = map(int, input().split())
num_p = [2**(i+1)-1 for i in range(N+1)]
num_layer = [2**(i+2)-3 for i in range(N+1)]
def f(N, X):
    if N == 0:
        if X == 0:
            return 0
        else:
            return 1
    elif X == 1:
        return 0
    elif X <= 1 + num_layer[N-1]:
        return f(N-1, X-1)
    elif X == 2 + num_layer[N-1]:
        return 1 + num_p[N-1]
    elif X < 2 + 2 * num_layer[N-1]:
        return num_p[N-1] + 1 + f(N-1, X - 2 - num_layer[N-1])
    else:
        return 2 * num_p[N-1] + 1
print(f(N, X))

Solution (Python):
n,x=map(int,input().split())
k=[1]*51
d=[1]*51
for i in range(1,51):
    k[i]=2*k[i-1]+3
    d[i]=2*d[i-1]+1
def f(n,x):
    if n==0:
        return 1
    if x==1:
        return 0
    if x<2+k[n-1]:
        return f(n-1,x-1)
    if x==2+k[n-1]:
        return d[n-1]+1
    if x<2+2*k[n-1]:
        return d[n-1]+1+f(n-1,x-2-k[n-1])
    else:
        return 2*d[n-1]+1
print(f(n,x))

Solution (Python):
def a(n):
    return 2 ** (n + 2) - 3

def p(n):
    return 2 ** (n + 1) - 1

def f(l, x):
    if l == 0:
        return 1
    elif x == 1:
        return 0
    elif 1 < x <= 1 + a(l-1):
        return f(l-1, x-1)
    elif x == 2 + a(l-1):
        return p(l-1) + 1
    elif 2 + a(l-1) < x <= 2 + 2 * a(l-1):
        return p(l-1) + 1 + f(l-1, x - (2 + a(l-1)))
    else:
        return 2 * p(l-1) + 1

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

Solution (Python):

m={}
def bits(n):
    if n in m:
        return m[n]
    elif n==0:
        m[n]=1
        return 1
    else:
        m[n]=((1+bits(n-1))*2+1)
        return m[n]
c={}
def pat(n):
    if n in c:
        return c[n]
    elif n==0:
        c[n]=1
        return c[n]
    else:
        c[n]=1+pat(n-1)*2
        return c[n]

def func(n, x):
    if n==0:
        return 1
    if x <=1:
        return 0
    elif x-1 <= bits(n-1):
        return func(n-1, x-1)
    elif x-1-bits(n-1)<=1:
        return pat(n-1)+1
    else:
        return pat(n-1)+1+func(n-1, x-1-bits(n-1)-1)

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


print(func(n, x))

Solution (Python):
N,X=map(int,input().split())

a,p=[1],[1]
for i in range(N):
    a.append(a[i]*2+3)
    p.append(p[i]*2+1)

def f(N,X):
    if N==0:
        return 0 if X<=0 else 1
    elif X<=1+a[N-1]:
        return f(N-1,X-1)
    else:
        return p[N-1]+1+f(N-1,X-2-a[N-1])

print(f(N,X))

Solution (Python):
N,X = map(int,input().split())

burger_len = [1]*(N+1)
burger_putty = [1]*(N+1)
for i in range(1,N+1):
    burger_len[i] = 3 + 2*burger_len[i-1]
    burger_putty[i] = 1 + 2*burger_putty[i-1]

def get_x(n,x):
    if n == 0:
        return int(x>0)
    tmp_len = burger_len[n-1]
    if x <= (tmp_len +1):
        return get_x(n-1,x-1)
    elif x == tmp_len + 2:
        return 1 + burger_putty[n-1]
    else:
        return burger_putty[n-1] + 1 + get_x(n-1,x-tmp_len-2)

print(get_x(N,X))

Solution (Python):


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

total = [1] + [0] * N
psum = [1] + [0] * N
for i in range(1, N + 1):
    total[i] = total[i - 1] * 2 + 3
    psum[i] = psum[i - 1] * 2 + 1


def f(k, x):
    if x == 0:
        return 0
    if k == 0:
        assert x == 1
        return 1

    ret = 0

    
    if x <= 1:
        return ret
    x -= 1

    
    
    
    if x <= total[k - 1]:
        return ret + f(k - 1, x)
    ret += psum[k - 1]
    x -= total[k - 1]

    
    if x < 1:
        return ret
    ret += 1
    x -= 1

    
    if x <= total[k - 1]:
        return ret + f(k - 1, x)
    ret += psum[k - 1]
    x -= total[k - 1]

    
    assert x <= 1
    return ret

print(f(N, X))

Solution (Python):
N, X = map(int, input().split())
a, p = [1], [1]

for i in range(50):
    a.append(a[i]*2+3)
    p.append(p[i]*2+1)

def Burger(N, X):
    if N == 0:
        return 1
    if X == 1:
        return 0
    elif 1 < X <= a[N-1]+1:
        return Burger(N-1, X-1)
    elif X == a[N-1]+2:
        return p[N-1]+1
    else:
        return p[N-1]+1+Burger(N-1, X-2-a[N-1])

print(Burger(N, X))

Solution (Python):
N,X = map(int,input().split())
bg_cnt = [1]
pan_cnt = [1]
for i in range(N):
    bg_cnt.append(bg_cnt[i] * 2 + 3)
    pan_cnt.append(pan_cnt[i] * 2 + 1)

def f(N,X):
    if N == 0:
        return 1
    elif X == 1:
        return 0
    elif X <= 1 + bg_cnt[N-1]:
        return f(N-1,X-1)
    elif X == 2 + bg_cnt[N-1]:
        return 1 + f(N-1,X-1)
    else:
        return pan_cnt[N-1] + 1 + f(N-1,X-2-bg_cnt[N-1])    
print(f(N,X))

Solution (Python):



import sys
import math


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

cntr = [1]
keta = [1]

for i in range(n):
  cntr.append(cntr[-1]*2+1)
  keta.append(keta[-1]*2+3)

ans = 0
for i in range(n,-1,-1):
  if x >= cntr[i]:
    ans += 2**i
    x -= cntr[i]
  else:
    x -= 1
print(ans)

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007


def A():
    return


def B():
    return


def C():
    d, g = LI()
    pc = LIR(d)
    g = g // 100
    max_ = 0
    for i in range(d):
        pc[i][1] = pc[i][1] // 100
        max_ = max(pc[i][0], max_)
    dp = [float("INF") for i in range(g+1)]
    skip = [0 for i in range(max_+1)]
    if d >= g:
        print(1)
        return
    dp[0] = 1
    for i in range(d):
        skip[pc[i][0]] = max(skip[pc[i][0]], pc[i][1] + i + 1)
    x = 0
    for k in range(max_+1):
        if x <= skip[k]:
            for i in range(x + 1, skip[k] + 1):
                if i > g:
                    break
                dp[i] = k
            x = skip[k]
    for i in range(d + 1):
        dp[i] = 1
    i = d
    y = d
    while i < g:    
        for x in range(d):
            continue
        
        
     


    
    return


def D():
    N, X = LI()
    def dfs(n, x):
        
        if x == 1 and n > 0:
            return 0 
        elif x < 2 ** (n + 1) - 1:
            return dfs(n - 1, x - 1)
        elif x == 2 ** (n + 1) - 1:
            return 2 ** n 
        elif x == 2 ** (n + 2) - 3:
            return 2 ** (n + 1) - 1
        else:
            return dfs(n - 1, x - 2 ** (n + 1) + 1) + 2 ** n 
    a = dfs(N, X)
    print(a)
        
    return



def E():
    return


def F():
    return


def G():
    return


def H():
    return


if __name__ == '__main__':
    D()

Solution (Python):
def rec(L, X):
    S = [0 for i in range(51)]
    S[0] = 1
    for i in range(1, 51):
        S[i] = 3 + 2 * S[i - 1]
    dic = {}
    def f(L, X):
        if L == 0:
            return 1
        if X < 2:
            return 0
        if (L, X) in dic:
            return dic[(L, X)]
        if X < S[L - 1] + 1:
            dic[(L, X)] = f(L - 1, X - 1)
        elif X == S[L - 1] + 1:
            dic[(L, X)] = f(L - 1, S[L - 1])
        elif X == S[L - 1] + 2:
            dic[(L, X)] = f(L - 1, S[L - 1]) + 1
        else:
            dic[(L, X)] = f(L - 1, S[L - 1]) + 1 + f(L - 1, X - 2 - S[L - 1])
        return dic[(L, X)]
    return f(L, X)

L, X = map(int, input().split())
print(rec(L, X))

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007


def A():
    return


def B():
    return


def C():
    n,k = LI()
    h = IR(n)
    h.sort()
    ans = float("inf")
    for i in range(n-k+1):
        ans = min(ans,h[i+k-1]-h[i])
    print(ans)


def D():
    n,x = LI()
    l = [1 for i in range(n+1)]
    for i in range(n):
        l[i+1] = 2*l[i]+3
    p = [1 for i in range(n+1)]
    for i in range(n):
        p[i+1] = 2*p[i]+1
    ans = 0
    for i in range(1,n+1)[::-1]:
        if i == 1:
            if x == 5:ans += 3
            else:ans += max(0,x-1)
        else:
            if x == 0:continue
            if x == l[i]:
                ans += p[i]
                x = 0
            if x > l[i-1]+1:
                ans += p[i-1]+1
                x -= l[i-1]+2
            else:
                x -= 1
    print(ans)

def E():
    return


def F():
    return


def G():
    return


def H():
    return


if __name__ == "__main__":
    D()

Solution (Python):
n, x = map(int, input().split())
 
P = [0] * (n + 1)
P[0] = 1
for i in range(1, n + 1):
    P[i] = P[i - 1] * 2 + 1

A = [0] * (n + 1)
A[0] = 1
for i in range(1, n + 1):
    A[i] = A[i - 1] * 2 + 3



 
def dfs(n, x):
    if n == 0:
        return 1
    if x == 1:
        return 0
    elif 1 < x <= 1 + A[n - 1]:
        return dfs(n - 1, x - 1)
    elif x == 1 + A[n - 1] + 1:
        return P[n - 1] + 1
    elif 1 + A[n - 1] + 1 < x < 1 + A[n - 1] + 1 + A[n - 1] + 1:
        return P[n - 1] + 1 + dfs(n - 1, x - 1 - A[n - 1] - 1)
    elif x >= 1 + A[n - 1] + 1 + A[n - 1] + 1:
        return P[n - 1] + 1 + P[n - 1]
    
print(dfs(n, x))

Solution (Python):
n, x = map(int, input().split())
 
P = [0] * (n + 1)
P[0] = 1
for i in range(1, n + 1):
    P[i] = P[i - 1] * 2 + 1

A = [0] * (n + 1)
A[0] = 1
for i in range(1, n + 1):
    A[i] = A[i - 1] * 2 + 3



 
def dfs(n, x):
    if n == 0:
        return 1
    if x == 1:
        return 0
    elif x <= 1 + A[n - 1]:
        return dfs(n - 1, x - 1)
    elif x == 1 + A[n - 1] + 1:
        return P[n - 1] + 1
    elif 1 + A[n - 1] + 1 < x < 1 + A[n - 1] + 1 + A[n - 1] + 1:
        return P[n - 1] + 1 + dfs(n - 1, x - 1 - A[n - 1] - 1)
    elif x >= 1 + A[n - 1] + 1 + A[n - 1] + 1:
        return P[n - 1] + 1 + P[n - 1]
    
print(dfs(n, x))

Solution (Python):
n, x = map(int, input().split())

P = [0] * (n + 1)
P[0] = 1
A = [0] * (n + 1)
A[0] = 1
for i in range(1, n + 1):
    P[i] = P[i - 1] * 2 + 1
    A[i] = A[i - 1] * 2 + 3




def dfs(n, x):
    if n == 0:
        if x <= 0:
            return 0
        else:
            return 1
    elif x <= 1 + A[n - 1]:
        return dfs(n - 1, x - 1)
    else:
        return P[n - 1] + 1 + dfs(n - 1, x - 1 - A[n - 1] - 1)

print(dfs(n, x))

Solution (Python):
n, x = map(int, input().split())

P = [0] * (n + 1)
P[0] = 1
for i in range(1, n + 1):
    P[i] = P[i - 1] * 2 + 1

A = [0] * (n + 1)
A[0] = 1
for i in range(1, n + 1):
    A[i] = A[i - 1] * 2 + 3




def dfs(n, x):
    cnt = 0
    if n == 0:
        return 1
    if x == 1:
        cnt += 0
    elif x <= 1 + A[n - 1]:
        cnt += dfs(n - 1, x - 1)
    elif x == 1 + A[n - 1] + 1:
        cnt += P[n - 1] + 1
    elif 1 + A[n - 1] + 1 < x < 1 + A[n - 1] + 1 + A[n - 1] + 1:
        cnt += P[n - 1] + 1 + dfs(n - 1, x - 1 - A[n - 1] - 1)
    elif x >= 1 + A[n - 1] + 1 + A[n - 1] + 1:
        cnt += P[n - 1] + 1 + P[n - 1]
    return cnt

print(dfs(n, x))

Solution (Python):
n, x = map(int, input().split())
h=[1]*(n+1)
p=[1]*(n+1)
for i in range(1, n+1):
    h[i]=3+h[i-1]*2
for i in range(1, n+1):
    p[i]=p[i-1]*2+1
def f(m, y):
    if m==0:
        return 1
    if y==1:
        return 0
    if y<=h[m-1]+1:
        return f(m-1, y-1)
    if y==h[m-1]+2:
        return p[m-1]+1
    if y<=h[m-1]*2+2:
        return f(m-1, y-h[m-1]-2)+p[m-1]+1
    if y==h[m-1]*2+3:
        return p[m-1]*2+1
print(f(n,x))

Solution (Python):
N, X = map(int, input().split())
a = [1]
p = [1]
for i in range(N):
	a.append(a[i]*2+3)
	p.append(p[i]*2+1)

def f(N, X):
	if N == 0:
		return 0 if X <= 0 else 1
	elif X <= a[N-1]+1:
		return f(N-1, X-1)
	elif X == a[N-1]+2:
		return p[N-1] + 1
	elif a[N-1]+3 <= X <= 2*a[N-1]+2:
		return f(N-1, X-2-a[N-1]) + p[N-1] + 1
	else:
		return p[N]

print(f(N, X))

Solution (Python):
N,X=map(int,input().split())
l=[2**(i+2)-3 for i in range(N+1)]
p=[2**(i+1)-1 for i in range(N+1)]
def f(n,x):
    if n==0:
        return 1
    elif x==1:
        return 0
    elif 1<x<=l[n-1]+1:
        return f(n-1,x-1)
    elif x==l[n-1]+2:
        return p[n-1]+1
    elif l[n-1]+2<x<l[n]:
        return p[n-1]+1+f(n-1,x-l[n-1]-2)
    elif x==l[n]:
        return p[n]
print(f(N,X))

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

p_num = []
pb_num = []
for i in range(n+1):
  if i == 0:
    p_num.append(1)
    pb_num.append(1)
  else:  
    p_num.append(p_num[-1] * 2 + 1)
    pb_num.append(pb_num[-1] * 2 + 3)
    
def get_p_num(n, x):
  if n == 0 and x == 1:
    return 1
  
  if x == 1:
    return 0
  elif x < (pb_num[n] + 1)//2:
    return get_p_num(n-1, x-1)
  elif x == (pb_num[n] + 1)//2:
    return p_num[n-1] + 1
  elif x < pb_num[n]:
    return p_num[n-1] + 1 + get_p_num(n-1, x - pb_num[n-1] - 2)
  else:
    return p_num[n-1] * 2 + 1
                 
print(get_p_num(n, x))

Solution (Python):
N, X = map(int, input().split(' '))
height = [1]

for i in range(N):
	height.append(height[-1]*2 + 3)

def patty(N,X):
	if N==1:
		l = [0,1,2,3,3]
		return l[X-1]
	elif N>=2:
		if X == 1:
			return 0
		elif X <= height[N-1]+1:
			return patty(N-1,X-1)
		elif X == height[N-1]+2:
			return patty(N-1,height[N-1])+1
		elif X == height[N]:
			return patty(N-1,height[N-1])*2+1
		elif X >= height[N-1]+3:
			return patty(N-1,height[N-1])+1+ patty(N-1,X-2-height[N-1])

print(patty(N,X))

Solution (Python):
n,x = map(int,input().split())

def f(N,X):
    if N == 0:
        return 0 if X <= 0 else 1
    elif X <= 4*(2**(N-1))-2:
        return f(N-1,X-1)
    elif X == 4*(2**(N-1))-1:
        return 2**N
    elif X <= 4*2**N - 3:
        return 2**N + f(N-1,X - 4*(2**(N-1)) + 1)
    else:
        return 2**(N+1) - 1

print(f(n,x))

Solution (Python):
N, X = [int(x) for x in input().split()]
INF = 10**9

layer_num = [1]
p = [1]

for i in range(N):
    layer_num.append(layer_num[-1]*2+3)
    p.append(p[-1]*2+1)


def rec(n, x):
    if x == 0:
        return 0
    if n == 0:
        return 1
    elif x <= layer_num[n-1]+1:
        return rec(n-1, x-1)
    else:
        return p[n-1] + 1 + rec(n-1, x-(layer_num[n-1]+2))


print(rec(N, X))

Solution (Python):
N, X = map(int, input().split())
result = [[]] * (N + 1)
result[0] = [1, 1] 
for i in range(1, N + 1):
    result[i] = [
        result[i - 1][0] * 2 + 3,
        result[i - 1][1] * 2 + 1,
    ]

def count_patty(idx, remain):
    if remain >= result[idx][0]:
        return result[idx][1]
    if remain <= 1:
        return 0
    ret = 0
    if remain >= result[idx][0] // 2 + 1:
        ret += result[idx - 1][1]
        ret += 1
        remain -= result[idx][0] // 2
    ret += count_patty(idx - 1, remain - 1)
    return ret

print(count_patty(N, X))

Solution (Python):
N, X = map(int, input().split())

a, p = [1], [1]

for i in range(N):
    a.append(2*a[i] + 3)
    p.append(2*p[i] + 1)

def burger(N, X):
    if N == 0:
        return 0 if X <= 0 else 1

    elif X <= 1 + a[N-1]:
        return burger(N-1, X-1)

    else:
        return p[N-1] + 1 + burger(N-1, X-2-a[N-1])

print(burger(N, X))

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(N, X):
    @lru_cache(maxsize=None)
    def p(n):
        if n == 0:
            return 1
        return 2*p(n-1) + 1
    
    @lru_cache(maxsize=None)
    def a(n):
        if n == 0:
            return 1
        return 2*a(n-1) + 3
    
    def f(n, x):
        if x == 1:
            return 0
        
        elif x < a(n-1)+1:
            return f(n-1, x-1)
        
        elif x == a(n-1) + 1:
            return p(n-1)

        elif x == a(n-1) + 2:
            return p(n-1) + 1

        elif x < a(n) - 2:
            return p(n) - f(n-1, a(n)-x-1)
        
        else:
            return p(n)
    
    return f(N, X)



def main():
    N, X = read_int_n()
    print(slv(N, X))

    
    
    


if __name__ == '__main__':
    main()

Solution (Python):

def p(i: int) -> int:
    """レベルiバーガーのパティの数
    p[i] = 2*p[i-1] + 1
    p[i] + 1 = 2*(p[i-1] + 1)
    p[i] + 1 = (2**i)*(p[0] + 1)
    p[i] + 1 = (2**i)*2
    p[i] = 2**(i+1) - 1
    """
    return 2**(i+1) - 1


def a(i: int) -> int:
    """レベルiバーガーの層の数(パティとパンの数)
    a[i] = 2*a[i-1] + 3
    a[i] + 3 = 2 * (a[i-1] + 3)
    a[i] + 3 = (2**i) * (a[0] + 3)
    a[i] + 3 = (2**i) * 4
    a[i] = (2**(i+2)) - 3
    """
    return 2**(i+2) - 3


def f(N: int, X: int) -> int:
    """レベルNバーガーの下からX層の中に含まれるパティの数
    :param N: バーガーのレベル
    :param X: パティの数を調べたい層の数
    :return: パティの数
    """
    if N == 0:
        return 1 if X > 0 else 0

    an = a(N)
    if X < an // 2 + 1:
        
        return f(N-1, X-1)
    if X == an // 2 + 1:
        
        return 1 + p(N-1)
    
    
    return 1 + p(N-1) + f(N-1, X-(an // 2 + 1))


if __name__ == "__main__":
    N, X = map(int, input().split())
    ans = f(N, X)
    print(ans)

Solution (Python):
N,X = (int(x) for x in input().split())

b_num_arr = [1]
p_num_arr = [1]
for i in range(1, 51):
    b_num_arr.append(b_num_arr[-1]*2+3)
    p_num_arr.append(p_num_arr[-1]*2+1)


def burger_eat(n, x):
    if x == 0:
        return 0
    if n == 0:
        return 1
    x -= 1
    if x < b_num_arr[n-1]:
        return burger_eat(n-1, x)
    pre_eat = p_num_arr[n-1]
    x -= b_num_arr[n-1]
    if x == 0:
        return pre_eat
    x -= 1
    pre_eat += 1
    return pre_eat + burger_eat(n-1, x)

ans = burger_eat(N, X)

print(ans)

Solution (Python):
N, X = map(int, input().split())

C, P = [1], [1]
for _ in range(N):
    C.append(C[-1]*2 + 3)
    P.append(P[-1]*2 + 1)

def f(n, x):
    if n==0:
        return 0 if x <= 0 else 1
    elif x <= C[n]//2:
        return f(n-1,x-1)
    elif x == C[n]//2+1:
        return P[n-1]+1
    else:
        return P[n-1]+1+f(n-1,x - C[n-1] - 2)

print(f(N,X))

Solution (Python):
N, X = map(int, input().split())

def rep(N,X):
    if N == 1:
        if X == 1:
            return(0)
        elif X == 5:
            return(3)
        else:
            return(X-1)
    elif X == 1:
        return(0)
    else:
        n = 2**(N+2)-3
        p = 2**N-1 
        if X <= n//2:
            return(rep(N-1, X-1))
        elif X == n//2+1:
            return(p + 1)
        else:
            if n-1 == X-1:
                return(rep(N-1, X-1-n//2-1) + p + 1)
            else:
                return(rep(N-1, X-1-n//2) + p + 1)
print(rep(N,X))

Solution (Python):
N,K=map(int,input().split())
L=[1]
P=[1]
BG=[0]
for i in range(1,N+1):
  L.append(L[i-1]*2+3)
  P.append(P[i-1]*2+1)
def f(x,y):
  if x==0:
    if y==0:
      return 0
    if y==1:
      return 1
  elif y<=1:
    return 0
  elif 1<y<=L[x-1]+1:
    return f(x-1,y-1)
  elif L[x-1]+1<y<L[x]:
    return P[x-1]+1+f(x-1,y-2-L[x-1])
  elif y==L[x]:
    return P[x]
print(f(N,K))

Solution (Python):
N,X=map(int,input().split())
a,p=[1],[1]
for i in range(N):
    a.append(a[i]*2+3)
    p.append(p[i]*2+1)
def f(n,x):
    if n==0:return 0 if x<=0 else 1
    elif x<=1+a[n-1]:return f(n-1,x-1)
    else:return p[n-1]+1+f(n-1,x-2-a[n-1])
print(f(N,X))