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):
a = [1]
b = [1]
for _ in range(50):
    a.append(2 * a[-1] + 3)
    b.append(2 * b[-1] + 1)

def num_of_patties(n, x):
    if n == 0:
        return 1

    if x == 1:
        return 0
    elif x <= a[n-1] + 1:
        return num_of_patties(n-1, x-1)
    elif x == a[n-1] + 2:
        return b[n-1] + 1
    elif x <= 2 * a[n-1] + 2:
        return b[n-1] + 1 + num_of_patties(n-1, x-a[n-1]-2)
    else:
        return b[n]


print(num_of_patties(*[int(i) for i in input().split()]))

Solution (Python):
N,X=list(map(int, input().split()))
A=[0]*(N+1)
P=[0]*(N+1)
A[0]=1
P[0]=1

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



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

print(burguer(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())

def A(x):
  return pow(2, x+2)-3

def P(x):
  return pow(2, x+1)-1

def f(n, x):
  if n==0:
    return 1
  if n==1:
    return min(x-1, 3)
  if x<=n:
    return 0
  if A(n)//2+1==x:
    return P(n-1)+1
  if A(n)==x:
    return P(n)
  if A(n)//2>=x:
    return f(n-1, x-1)
  return P(n-1)+1+f(n-1, x-A(n)//2-1)

print(f(N, X))

Solution (Python):
def examA():
    N = DI()/dec(7)
    ans = N
    print(N)
    return

def examB():
    ans = 0
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    N, X = LI()
    S = [0]*(N+1)
    P = [0]*(N+1)
    S[0] = 1; P[0] = 1
    for i in range(N):
        S[i+1] = S[i]*2 + 3
        P[i+1] = P[i]*2 + 1

    def dfs(n,x):
        if n==0:
            return 0<x
        if x>=S[n-1]+2:
            return 1 + P[n-1] + dfs(n-1,x-2-S[n-1])
        return dfs(n-1,x-1)
    ans = int(dfs(N,X))
    print(ans)
    return

from decimal import getcontext,Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = dec("0.000000000001")
alphabet = [chr(ord('a') + i) for i in range(26)]
alphabet_convert = {chr(ord('a') + i): i for i in range(26)}

getcontext().prec = 28

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examD()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Solution (Python):
N, X = map(int, input().split())
L, C = [1], [1]
for n in range(1,N+1):
    L.append(2*L[-1]+3)
    C.append(2*C[-1]+1)
C.append(0)
step = 0
res = 0
for i in reversed(range(N+1)):
    if X<=step+L[i]//2:
        step+=1
    elif X>step+L[i]//2+1:
        step += L[i]//2+1
        res += C[i-1]+1
    else:
        res += C[i-1]+1
        break
print(res)

Solution (Python):

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

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

def pbx(xx,nn):

    if nn==0:
        return 1
    if xx==1:
        return 0
    elif xx<=1+pb[nn-1][0]:
        return pbx(xx-1,nn-1)
    elif xx==2+pb[nn-1][0]:
        return pb[nn-1][1]+1
    elif xx<=2+pb[nn-1][0]*2:
        xxx=pbx(xx-pb[nn-1][0]-2,nn-1)

        xxx=pb[nn-1][1]+1+xxx

        return xxx
    elif xx==3+pb[nn-1][0]*2:
        return pb[nn][1]
    else:
        print("----------",xx,nn)
        return 0

    
print(pbx(x,n))

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

def func(m,y):
  if y==0:return 0
  ret=0
  t=4*pow(2,m)-3
  if y>=t-1:
    ret=pow(2,m+1)-1
  elif y==(t-1)//2:
    ret=pow(2,m)-1
  elif y==(t-1)//2+1:
    ret=pow(2,m)
  elif y>(t-1)//2+1:
    ret=pow(2,m)
    ret+=func(m-1,y-(t-1)//2-1)
  else:
    ret=func(m-1,y-1)
  return ret

print(func(n,x))

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






P = [0] * 51
B = [0] * 51

P[0] = 1
B[0] = 1

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


def get_whole_barger(n):
  return P[n]


def get_patty(n,x):
  if n == 0 or x == 0:
    return P[0]
  if B[n] == x:
    return P[n]
  if x <= 1:
    return 0
  if x <= 1 + B[n - 1]:
    return get_patty(n - 1, x - 1)
  if x <= 2 + B[n - 1]:
    return get_whole_barger(n - 1) + 1
  if x <= 2 + B[n - 1] * 2:
    return get_whole_barger(n - 1) + 1 + get_patty(n - 1, x - 2 - B[n - 1])
  else:
    return get_whole_barger(n - 1) + 1 + get_whole_barger(n - 1)

print(get_patty(N,X))

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

L = [1]
P = [1]

for i in range(N):
    L.append(L[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 + L[N-1]:
        return f(N-1, X-1)
    else:
        return P[N-1] + 1 + f(N-1, X-2-L[N-1])

print(f(N, K))

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

Solution (Python):
import sys
from functools import lru_cache

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, X = map(int, readline().split())

    A = [0] * (N + 1)
    B = [0] * (N + 1)
    A[0] = B[0] = 1
    for i in range(N):
        A[i + 1] = 2 * A[i] + 3
        B[i + 1] = 2 * B[i] + 1

    def rec(i, x):
        if i == 0:
            return 1 if x > 0 else 0
        elif x <= 1 + A[i - 1]:
            return rec(i - 1, x - 1)
        else:
            return B[i - 1] + 1 + rec(i - 1, x - 2 - A[i - 1])

    print(rec(N, X))
    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys
from functools import lru_cache

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, X = map(int, readline().split())

    @lru_cache(maxsize=None)
    def rec1(i):
        if i == 0:
            return 1
        else:
            return 2 * rec1(i - 1) + 1

    @lru_cache(maxsize=None)
    def rec2(i):
        if i == 0:
            return 1
        else:
            return 2 * rec2(i - 1) + 3

    def rec(i, x):
        if x <= 0:
            return 0
        if i == 0:
            return 1

        x -= 1
        ans = 0
        if x > rec2(i - 1):
            x -= rec2(i - 1)
            ans += rec1(i - 1)
        else:
            ans += rec(i - 1, x)
            return ans

        if x > 0:
            x -= 1
            ans += 1
        else:
            return ans

        if x > rec2(i - 1):
            x -= rec2(i - 1)
            ans += rec1(i - 1)
        else:
            ans += rec(i - 1, x)

        return ans

    print(rec(N, X))
    return


if __name__ == '__main__':
    main()

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
from math import sqrt
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

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






N, X = getNM()


cnt_burger = [[0 for i in range(2)] for i in range(51)]
cnt_burger[0] = [1, 1]
for i in range(1, 51):
    cnt_burger[i][0] = 1 + cnt_burger[i - 1][1] + 1
    cnt_burger[i][1] = cnt_burger[i][0] + cnt_burger[i - 1][1] + 1


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



def count(n, x):
    
    if n == 0 and x == 1:
        return 1

    
    if x == 1:
        return 0

    
    elif 1 < x < cnt_burger[n][0]:
        
        return count(n - 1, x - 1)

    
    elif x == cnt_burger[n][0]:
        return cnt_patty[n - 1] + 1

    
    elif cnt_burger[n][0] < x < cnt_burger[n][1]:
        return cnt_patty[n - 1] + 1 + count(n - 1, x - cnt_burger[n][0])

    
    else:
         return 2 * cnt_patty[n - 1] + 1

print(count(N, X))

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

def level_n_putty(n):
    if n == 0:
        return 1
    else:
        return 2 * level_n_putty(n-1) + 1

def level_n_hb(n):
    if n == 0:
        return 1
    else:
        return 2 * level_n_hb(n-1) + 3

m = level_n_hb(n)

s = 0
base = 0

while True:
    if x == base + 1:
        if n == 0:
            s += 1
        break
    elif x == base + m:
        s += level_n_putty(n)
        break
    else:
        l = level_n_hb(n-1)
        
        if x < base + l + 2:
            base += 1
            n -= 1
            m = l
        elif x == base + l + 2:
            s += 1 + level_n_putty(n-1)
            break
        else:
            base = base + l + 2
            s += 1 + level_n_putty(n-1)
            n -= 1
            m = l

print(s)

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

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

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

print(f(N, X))

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

pate, slice = [1], [1]
for _ in range(n + 1):
    pate.append(2 * pate[-1] + 1)
    slice.append(2 * slice[-1] + 3)

ans = 0
while n > 0:
    if x >= slice[n - 1] + 2:
        ans += pate[n - 1] + 1
        x -= slice[n - 1] + 2
    elif x < slice[n - 1] + 2:
        x -= 1
    n -= 1
print(ans + (x > 0))

Solution (Python):
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())


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])

n, x = MAP()
a = [0]*n
p = [0]*n
a[0] = 1
p[0] = 1
for i in range(1, n):
    a[i] = a[i-1]*2 + 3
    p[i] = p[i-1]*2 + 1

print(f(n, x))

Solution (Python):
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())


def dfs(k):
    global count, ans
    
    count += 1
    if k == 0:
        ans += 1
    elif count < x:
        
        if count + b[k-1] > x:
            dfs(k-1)
        else:
            count += b[k-1]
            ans += p[k-1]
        if count < x:
            
            count += 1
            ans += 1
            if count < x:
                
                if count + b[k-1] > x:
                    dfs(k-1)
                else:
                    count += b[k-1]
                    ans += p[k-1]

n, x = MAP()
b = [0]*n
p = [0]*n
b[0] = 1
p[0] = 1
for i in range(1, n):
    b[i] = b[i-1]*2 + 3
    p[i] = p[i-1]*2 + 1

count = 0
ans = 0
dfs(n)
print(ans)

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

burger = [1]
patty = [1]
for i in range(N):
    burger.append(burger[i]*2 + 3)
    patty.append(patty[i]*2 + 1)
    
def f(N, X):
    if N == 0:
        if X <= 0:
            return 0
        else:
            return 1
    elif X <= burger[N-1] + 1:
        return f(N-1, X-1)
    else:
        return patty[N-1] + 1 + f(N-1, X-2-burger[N-1])

ans = f(N, X)
print(ans)

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

pate, slice = [1], [1]
for _ in range(n):
    pate.append(2 * pate[-1] + 1)
    slice.append(2 * slice[-1] + 3)

ans = 0
for i in range(n)[::-1]:
    if x >= slice[i] + 2:
        ans += pate[i] + 1
        x -= slice[i] + 2
    elif x < slice[i] + 2:
        x -= 1
print(ans + (x > 0))

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

pate, slice = [1], [1]
for _ in range(n + 1):
    pate.append(2 * pate[-1] + 1)
    slice.append(2 * slice[-1] + 3)

ans = 0
for i in range(n)[::-1]:
    if x >= slice[i] + 2:
        ans += pate[i] + 1
        x -= slice[i] + 2
    elif x < slice[i] + 2:
        x -= 1
print(ans + (x > 0))

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

pate, slice = [1], [1]
for _ in range(n + 1):
    pate.append(2 * pate[-1] + 1)
    slice.append(2 * slice[-1] + 3)

ans = 0
while n > 0:
    if x >= slice[n - 1] + 2:
        ans += pate[n - 1] + 1
        x -= slice[n - 1] + 2
    elif x < slice[n - 1] + 2:
        x -= 1
    n -= 1
print(ans + (x > 0))

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

pate, slice = [1], [1]
for _ in range(n + 1):
    pate.append(2 * pate[-1] + 1)
    slice.append(2 * slice[-1] + 3)

ans = 0
while n > 0:
    if x >= slice[n - 1] + 2:
        ans += pate[n - 1] + 1
        x -= slice[n - 1] + 2
    elif x < slice[n - 1] + 2:
        x -= 1
    n -= 1
print(ans + (x > 0))

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

pate, slice = [1], [1]
for _ in range(n + 1):
    pate.append(2 * pate[-1] + 1)
    slice.append(2 * slice[-1] + 3)

ans = 0
while n * x > 0:
    if x >= slice[n - 1] + 2:
        ans += pate[n - 1] + 1
        x -= slice[n - 1] + 2
    elif x < slice[n - 1] + 2:
        x -= 1
    n -= 1
print(ans + (x > 0))

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

pate, slice = [1], [1]
for _ in range(n + 1):
    pate.append(2 * pate[-1] + 1)
    slice.append(2 * slice[-1] + 3)

ans = 0
while n > 0 and x > 0:
    if x >= slice[n - 1] + 2:
        ans += pate[n - 1] + 1
        x -= slice[n - 1] + 2
    elif x < slice[n - 1] + 2:
        x -= 1
    n -= 1
print(ans + (x > 0))

Solution (Python):
import sys
 
sys.setrecursionlimit(10 ** 6)

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())

pate, slice = [1], [1]
for _ in range(n+1):
    pate.append(2 * pate[-1] + 1)
    slice.append(2 * slice[-1] + 3)

ans = 0
while n >= 0 and x > 0:
    if n == 0 and x > 0:
        ans += 1
        x -= 1
    elif x >= slice[n - 1] + 2:
        ans += pate[n - 1] + 1
        x -= slice[n - 1] + 2
    elif x < slice[n - 1] + 2:
        x -= 1
    n -= 1
print(ans)

Solution (Python):
A=[1]*51
for i in range(1,51):
    A[i]=2*A[i-1]+3

def T(N,x):
    if N==0:
        return 1
    elif x==1:
        return 0
    elif 2<=x<=A[N-1]+1:
        return T(N-1,x-1)
    elif x==A[N-1]+2:
        return T(N-1,A[N-1])+1
    elif A[N-1]+3<=x<=2*A[N-1]+2:
        return T(N-1,A[N-1])+1+T(N-1,x-(A[N-1]+2))
    else:
        return 2*T(N-1,A[N-1])+1

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

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

    if 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):
def cin():
    in_ = list(map(int,input().split()))
    if len(in_) == 1:  return in_[0]
    else:  return in_

N, X = cin()
a = [0 for _ in range(N)] 
p = [0 for _ in range(N)] 
a[0] = 1
p[0] = 1

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

ans = f(N, X)
print(ans)

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

sumx=[1]
pathi=[1]
for i in range(n):
  sumx+=[sumx[-1]*2+3]
  pathi+=[pathi[-1]*2+1]
  
if n==0:
  if x==1:
    print(1)
    exit()
    
elif x==1:
  print(0)
  exit()
  

elif x==sumx[-1] or x==sumx[-1]-1:
  print(pathi[-1])
  exit()
  
ans=0

for i in range(n-1,0,-1):
  x-=1
  if x>=sumx[i]:
    ans+=pathi[i]
    x-=sumx[i]
    if x>=1:
      x-=1
      ans+=1
    if x>=sumx[i]:
      ans+=pathi[i]
      x-=sumx[i]
      if x>=2:
        x-=2
        ans+=1


ans+=max(x-1,0)
print(ans)

Solution (Python):

        
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()

    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)
        else:
            return p[n-1]+1+f(n-1, x-2-a[n-1])

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





                
if __name__ == '__main__':
    main()

Solution (Python):
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

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 = [2 ** (i + 2) - 3 for i in range(n)]
burger2 = [2 ** (i + 1) - 1 for i in range(n)]
num = [0 for i in range(n)]
ans = 0
temp = n - 1
while x > 0:
    if x >= 1:
        x -= 1
    else:
        continue
    if x >= burger[temp]:
        num[temp] += 1
        x -= burger[temp]
    else:
        temp -= 1
        continue
    if x >= 1:
        ans += 1
        x -= 1
    else:
        continue
    if x >= burger[temp]:
        num[temp] += 1
        x -= burger[temp]
    else:
        temp -= 1
        continue
    if x >= 1:
        x -= 1
    else:
        continue
for i in range(n):
    ans += burger2[i] * num[i]
print(ans)

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
    if X == 1:
        return 0
    elif 1 < X <= 1 + a[N - 1]:
        return f(N - 1, X - 1)
    elif X == 2 + a[N - 1]:
        return p[N - 1] + 1
    elif 2 + a[N - 1] < X <= 2 + 2 * a[N - 1]:
        return p[N - 1] + 1 + f(N - 1, X - 2 - a[N - 1])
    elif X == 3 + 2 * a[N - 1]:
        return 2 * p[N - 1] + 1

print(f(N, X))

Solution (Python):
n,x=map(int,input().split())
l,p=[1],[1]
for i in range(n):
  l+=[l[-1]*2+3]
  p+=[p[-1]*2+1]
x-=1
a=1
while n:
  t=l[n]//2
  if x>=t:
    a+=p[n-1]+1
    x-=t
  x-=1
  n-=1
if x<0: a-=1
print(a)

Solution (Python):
n,x=map(int,input().split())
l,p=[1],[1]
for i in range(n):
  l+=[l[-1]*2+3]
  p+=[p[-1]*2+1]
x-=1
a=0
while x>0 and n:
  t=l[n]//2
  if x>=t:
    a+=p[n-1]+1
    x-=t
  x-=1
  n-=1
if x>=0 and n==0: a+=1
print(a)

Solution (Python):
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N, X = LI()
    X -= 1

    
    l = [0] * (N + 1)
    l[0] = 1
    for i in range(N):
        l[i+1] = 2 * l[i] + 3

    
    p = [0] * (N + 1)
    p[0] = 1
    for i in range(N):
        p[i+1] = 2 * p[i] + 1

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

    ans = rec(N, X)
    print(ans)

if __name__ == '__main__':
    resolve()

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

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

def pNumber(level, number):
    if level == 0:
        return 1
    if number == 1:
        return 0
    if number <= burgerLengthList[level][0] // 2:
        return pNumber(level - 1, number - 1)
    elif number == burgerLengthList[level][0] // 2 + 1:
        return pNumber(level - 1, number - 1) + 1
    else:
        return burgerLengthList[level - 1][1] + 1 + pNumber(level - 1, number - burgerLengthList[level - 1][0] - 2)

print(pNumber(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())

def n_pati(l):
  val = 1
  for i in range(l):
    val = val*2+1
  return val

def n_layer(l):
  val = 1
  for i in range(l):
    val = val*2+3
  return val

SUM=0
while 1:
  if N==1:
    if X in [0,1]:break
    elif X>=2:
      SUM += min(3,X-1)
      break
  
  L = n_layer(N)
  if X >= L//2:
    SUM += n_pati(N-1)
    X -= n_layer(N-1)+1
    if X==0:
      break
    SUM += 1
    X -= 1
    if X==0:
      break
    N -= 1
  else:
    X -= 1
    N -= 1
    
  if X in [0,1]:break
  
print(SUM)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, X = mapint()
burger = [1]*50
pa = [1]*50
for i in range(1, 50):
    burger[i] = burger[i-1]*2+3
    pa[i] = pa[i-1]*2+1

to_eat = X
layer = N
ans = 0
while 1:
    if layer==0:
        ans += to_eat
        break
    if to_eat<=1:
        break
    elif to_eat==burger[layer-1]+2:
        ans += pa[layer-1]+1
        break
    elif to_eat==burger[layer-1]+1:
        ans += pa[layer-1]
        break
    elif to_eat==burger[layer-1]*2+3:
        ans += pa[layer-1]*2+1
        break
    elif to_eat<=burger[layer-1]:
        layer -= 1
        to_eat -= 1
        continue
    else:
        ans += pa[layer-1]+1
        to_eat -= burger[layer-1]+2
        layer -= 1

print(ans)

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

def rec(n,x):
    if n==0:
        ret = int(x>0)
    elif x <= 1 + siz[n-1]:
        ret = rec(n-1, x-1)
    else:
        ret = pat[n-1] + 1 + rec(n-1, x-2-siz[n-1])
    return ret
print(rec(N,X))

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

Total = [1]
Patties = [1]

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

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

print(Burger(N,X))

Solution (Python):
memo1 = {}
def cho(n):
    if n==0:
        return 1
    if n in memo1:
        return memo1[n]
    memo1[n] = 2*cho(n-1)+3
    return memo1[n]
memo2 = {}
def pat(n):
    if n==0:
        return 1
    if n in memo2:
        return memo2[n]
    memo2[n] = 2*pat(n-1)+1
    return memo2[n]
N,X = map(int,input().split())
cnt = 0
k = N
while X>0:
    if X==1:
        if k==0:
            cnt += 1
        break
    elif X<=cho(k)//2:
        k -= 1
        X -= 1
    elif X==cho(k)//2+1:
        cnt += 1+pat(k-1)
        break
    elif X==cho(k):
        cnt += pat(k)
        break
    else:
        cnt += pat(k-1)+1
        X -= cho(k-1)+2
        k -= 1
print(cnt)

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

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

store = [pow(2,i+1)-1 for i in range(51)]

def maisu(n):
  return pow(2,n+2)-3

def burger(n,k): 
  if k == maisu(n):
    return store[n]
  elif k <= 1:
    return 0
  elif (maisu(n)-3)//2 +1 >= k:
    return burger(n-1,k-1)
  else:
    
    return burger(n-1,k-(2+maisu(n-1)))+burger(n-1,maisu(n-1))+1
  
ans = burger(N,K)    
print(ans)

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

burger_size = [1]
patty_num = [1]
for i in range(50):
    burger_size.append(2 * burger_size[-1] + 3)
    patty_num.append(2 * patty_num[-1] + 1)



def dfs(n, x):
    if burger_size[n] == x:
        return patty_num[n]

    if x == 1:
        return 0

    elif 1 < x <= 1 + burger_size[n - 1]:
        return dfs(n - 1, x - 1)

    elif x == 1 + burger_size[n - 1] + 1:
        return patty_num[n - 1] + 1

    elif 1 + burger_size[n - 1] + 1 < x < burger_size[n]:
        return patty_num[n - 1] + 1 + dfs(n - 1, x - burger_size[n - 1] - 2)


print(dfs(N, X))

Solution (Python):
n,x=map(int, input().split())
p=[1]*(n+1) 
a=[1]*(n+1) 

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

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

print(f(n,x))

Solution (Python):
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def main():
    N, X = NMI()
    A = [1]
    P = [1]
    for i in range(N):
        A.append(A[-1]*2+3)
        P.append(P[-1]*2+1)

    def rec(n, x):
        if n == 0:
            return 1

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

    print(rec(N, X))


if __name__ == "__main__":
    main()

Solution (Python):
def f(n, x, a, p):
    if n == 0:
        return 1 if x == 1 else 0

    elif x <= 1:
        return 0

    elif 1 < x <= 1 + a[n - 1]:
        return f(n - 1, x - 1, a, p)

    elif x == 2 + a[n - 1]:
        return p[n - 1] + 1

    elif 2 + a[n - 1] < x <= 2 + 2 * a[n - 1]:
        return p[n - 1] + 1 + f(n - 1, x - 2 - a[n - 1], a, p)

    else:
        return 1 + 2 * p[n - 1]


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

a = [1] * (n + 1)
p = [1] * (n + 1)

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

print(f(n, x, a, p))