TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: 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?

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

n,x=map(int,input().split())
a=[1]
p=[1]
for i in range(n-1):
    a.append(a[i]*2+3)
    p.append(p[i]*2+1)
def f(n,x):
  if n==0 and x=1:
    return 1
  elif n==0:
    return 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))

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

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
# coding: utf-8
# Your code here!
N,X=map(int,input().split())

def dfs(count,object):
    count+=1
    object="B"+object+"P"+object+"B"
    if count<N:
        dfs(count,object)
    else:
        print(object)
        exit()

n=0
burger="P"

(dfs(n,burger))


# coding: utf-8
# Your code here!
N,X=map(int,input().split())

X-=1
def saiki(i,x,count):
    if i==-1:
        print(int(count)+1)
        exit()
    all=2**(i+2)-3
    paty=2**(i+1)-1
    if x==all-1:
        print(count+paty)
        exit()
    elif x==0:
        print(count)
    elif x==(all-1)//2:
        print(int(count+(paty-1)//2+1))
        exit()
    elif x>(all-1)//2:
        count+=((paty-1)//2+1)
        x-=(all//2)
        saiki(i-1,x-1,count)
    elif x<(all-1)//2:
        saiki(i-1,x-1,count)
    

ans=0
saiki(N,X,ans)



Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
N,X = map(int,input().split())
a = ["P"]
def b(L):
    if L != 0:
        c = ["B"]
        return c+b(L-1)+a+b(L-1)+c
    else :
        return a
j = b(N)
q = j[:X]
q.count("P")

N,X = map(int,input().split())
def lb(N):
    if N != 0:
        return 2*lb(N-1)+3
    else:
        return 1
def pn(N):
    if N != 0:
        return 2*pn(N-1)+1
    else:
        return 1
def B(N,X):
    if X == 0:
        return 0
    elif N == 0:
      	return 1
    elif lb(N-1)+1 >= X:
        return B(N-1,X-1)
    else:
        return pn(N-1)+1+B(N-1,X-lb(N-1)-2)
print(B(N,X))


Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
import os, sys, re, math

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

memo_length = [0 for i in range(51)]
memo_patties = [0 for i in range(51)]
memo_length[0] = 1
memo_patties[0] = 1

for i in range(1,51):
    memo_length[i] = memo_length[i-1] * 2 + 3
    memo_patties[i] = memo_patties[i-1] * 2 + 1

def doit(level,x):
    if x == 0:
        return 0
    if x >= memo_length[level]:
        return memo_patties[level]

    tmp = memo_length[level-1]
    ret = 0

    if x >= 1:
        ret += doit(level-1, x-1)
    if x >= tmp + 2:
        ret += 1
        ret += doit(level-1, x-tmp-2)

    return ret

print(doit(N,X-1))

import os, sys, re, math

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

memo_length = [0 for i in range(51)]
memo_patties = [0 for i in range(51)]
memo_length[0] = 1
memo_patties[0] = 1

for i in range(1,51):
    memo_length[i] = memo_length[i-1] * 2 + 3
    memo_patties[i] = memo_patties[i-1] * 2 + 1

def doit(level,x):
    if x == 0:
        return 0
    if x >= memo_length[level]:
        return memo_patties[level]

    tmp = memo_length[level-1]
    ret = 0

    if x >= 1:
        ret += doit(level-1, x-1)
    if x >= tmp + 2:
        ret += 1
        ret += doit(level-1, x-tmp-2)

    return ret

print(doit(N,X))


Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
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)

# print(a, p)

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


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)

# print(a, p)

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])
print(f(N, X))


Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):

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

def rec(lv,ls):
    if lv == 0:
        return [1]
    else:
        ret = rec(lv-1,ls)
        for i in range(0,len(ret) -1):
            if ret[i]>0 and ret[i+1]>0:
                ret[i+1] += ret[i]
                ret[i] = 0  #deleted tag

        while 0 != ret.count(0):
            ret.remove(0)
        return [-1,*ret,1,*ret,-1]

 
count = 0
for e in rec(n, list() ):
    abs_e = abs(e)
    if x>=abs_e:
        x -= abs_e
        count += e if e>0 else 0
    else:
        count += e if e>0 else 0


print(count)



# This src was written after reading editional.pdf .

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


an, pn = [1], [1]

for i in range(n):
    an.append(2*an[i]+3)
    pn.append(2*pn[i]+1)

#print(an)

def f(n,x):

    #print(n,x)

    if n == 0:
        return 1 if 0<x else 0
    
    if x <= an[ n-1 ] + 1:
        return f( n-1, x-1 )

    else:# x <= 2*an[n-1] + 3:
        return f(n-1, x-an[n-1]-2) + pn[n-1] + 1


print(f(n,x))

    
#    else if: 


Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
n, x = map(int, input().split())
import numpy as np


def burger(num):
    if num == 1:
        return np.array([1, 3, 1])
    last_burger = burger(num - 1)
    return np.concatenate((last_burger[0] + 1, last_burger[1:], 1, last_burger[:-1], last_burger[-1] + 1), axis=None)


def main(n, x):
    burger_n = burger(n)
    print(burger_n)

    i, p, eaten = 0, 0, 0

    while eaten < x:
        eaten += burger_n[i]
        if i % 2 == 1:
            p += burger_n[i]
        i += 1

    if i % 2 == 0:
        p -= (eaten - x)

    print(p)


main(n, x)

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


def main(n, x):
    if n == 0:
        if x >= 0:
            return 1
        else:
            return 0
    if x == 0:
        return 0
    if x == 2 ** (n + 1) - 2:
        return 2 ** n
    if x < 2 ** (n + 1) - 2:
        return main(n - 1, x - 1)
    return 2 ** n + main(n - 1, x - (2 ** (n + 1) - 1))


print(main(n, x))

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
n,x=map(int,input().split())
a=[(1,1)]
for _ in range(n):
  a+=[(a[-1][0]*2+3,a[-1][1]*2+1)]

if a[-1][0]==x:
  print(a[-1][1])
  exit()

s=0
for i,j in a[::-1]:
  x-=1
  if i<=x:
    x-=i
    s+=j
    if x>=1:
      x-=1
      s+=1
print(s)

n,x=map(int,input().split())
a=[(1,1)]
for _ in range(n):
  a+=[(a[-1][0]*2+3,a[-1][1]*2+1)]

s=0
for i,j in a[::-1]:
  x-=1
  if i<=x:
    x-=i;s+=j
    if x>=1:
      x-=1;s+=1

print(s)


n,x=map(int,input().split())
a=[(1,1)]
for _ in range(n):
  a+=[(a[-1][0]*2+3,a[-1][1]*2+1)]

if a[-1][0] in (x,x-1):
  print(a[-1][1])
  exit()
a=a[:-1]
x-=1

s=0
for i,j in a[::-1]:
  x-=1
  if i<=x:
    x-=i;s+=j
    if x>=1:
      x-=1;s+=1
print(s)

n,x=map(int,input().split())
a=[(1,1)]
for _ in range(n):
  a+=[(a[-1][0]*2+3,a[-1][1]*2+1)]

s=0
for k in range(1,len(a)*2+1):
  i,j = a[-k // 2]
  x -= k % 2
  if i <= x:
    x-=i;s+=j
    if x>=1:
      x-=1;s+=1

print(s)


n,x=map(int,input().split())
a=[(1,1)]
for _ in range(n):
  a+=[(a[-1][0]*2+3,a[-1][1]*2+1)]

if a[-1][0] in (x,x-1):
  print(a[-1][1]);exit()

s=0
for k in range(3,len(a)*2+1):
  i,j = a[-k // 2]
  x -= k % 2
  if i <= x:
    x-=i;s+=j
    if x>=1:x-=1;s+=1

print(s)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
#coding:utf-8
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:
		return0 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))

#coding:utf-8
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))

Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
from functools import lru_cache
#@lru_cache(maxsize=3000)
@memoize
def burger(str_b,level):
  if(level == 0):
    return str_b + 'p'
  str_b += 'B'
  str_b = burger(str_b,level-1)
  str_b += 'p'
  str_b = burger(str_b,level-1)
  str_b += 'B'
  return str_b


str_b = ''
N,X = map(int,input().split())
str_b = burger(str_b,N)
b_list = list(str_b)
eat_list = b_list[::-1]
eat_list = b_list[0:X]
print(eat_list.count('p'))

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

  

Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
def count(n,x):
    print(n,x)
    if x<=n:
        return 0
    elif x>=2**(n+2)-2-n:
        return 2**(n+1)-1
    elif 2**(n+2)-3 > 2*x:
        return count(n-1,x-1)
    else:
        return 2**n + count(n-1,x-2**(n+1)+1)

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

def count(n,x):
    if x<=n:
        return 0
    elif x>=2**(n+2)-3-n:
        return 2**(n+1)-1
    elif 2**(n+2)-3 > 2*x:
        return count(n-1,x-1)
    else:
        return 2**n + count(n-1,x-2**(n+1)+1)

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

Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
# -*- coding: utf-8 -*-                                                                              

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


# -*- coding: utf-8 -*-                                                                              

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


Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
n,x=map(int,input().split())
a,p=[1],[1]
for i in range(n+1):
    a.append(3+2*a[-1])
    p.append(1+2*a[-1])
def f(l,x):
    if l==0:return int(x==1)
    if x<=1+a[n-1]:
        return  f(l-1,x-1)
    else:return p[l-1]+1+f(l-1,x-2-a[l-1])
print(f(n,x))

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

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

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
n,x = map(int,input().split())
dp_a=[1]
dp_p=[1]
for i in range(1,n):
  dp_a.append(2*dp_a[i-1] + 3)
  dp_p.append(2*dp_p[i-1] + 1)  
  
def burger(n,x):
  if n==0:
    if x==1:      
      return 1
    else:
      return 0
    
  if x < dp_a[n-1]+1:
    return burger(n-1, x-1)
  else:
    return dp_p[n-1] +1 +burger(n-1, x-dp_a[n-1]-2)  

burger(n,x)  

n,x = map(int,input().split())
dp_a=[1]
dp_p=[1]
for i in range(1,n):
  dp_a.append(2*dp_a[i-1] + 3)
  dp_p.append(2*dp_p[i-1] + 1)  
  
def burger(n,x):
  if n==0:
    if x <= 0:      
      return 0
    else:
      return 1
    
  if x <= dp_a[n-1]+1:
    return burger(n-1, x-1)
  else:
    return dp_p[n-1] +1 +burger(n-1, x-dp_a[n-1]-2)  

print(burger(n,x))

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
allEatCache = {}
lenBurgerCache = {}


def nOfPatty(level, eat):
    if level == 0:
        return 1
    else:
        if level in allEatCache and eat >= lenBurger(level):
            return allEatCache[level]
        else:
            lenOfLowerLevel = lenBurger(level - 1)
            if eat <= 1:
                return 0
            if 2 <= eat <= 1 + lenOfLowerLevel:
                return nOfPatty(level - 1, eat - 1)
            if eat == 1 + lenOfLowerLevel + 1:
                return nOfPatty(level - 1, eat - 1) + 1
            else:
                tmp = nOfPatty(level - 1, eat - 1) + 1
                tmp += nOfPatty(level - 1, eat - 1 - lenOfLowerLevel - 1)
                allEatCache[level] = tmp
                return tmp


def lenBurger(level):
    if level == 0:
        return 1
    else:
        if level in lenBurgerCache:
            return lenBurgerCache[level]
        else:
            return 3 + lenBurger(level - 1) * 2


print(nOfPatty(50, 4321098765432109))


allEatCache = {}
lenBurgerCache = {}


def nOfPatty(level, eat):
    if level == 0:
        return 1
    else:
        if level in allEatCache and eat >= lenBurger(level):
            return allEatCache[level]
        else:
            lenOfLowerLevel = lenBurger(level - 1)
            if eat <= 1:
                return 0
            if 2 <= eat <= 1 + lenOfLowerLevel:
                return nOfPatty(level - 1, eat - 1)
            if eat == 1 + lenOfLowerLevel + 1:
                return nOfPatty(level - 1, eat - 1) + 1
            else:
                tmp = nOfPatty(level - 1, eat - 1) + 1
                tmp += nOfPatty(level - 1, eat - 1 - lenOfLowerLevel - 1)
                allEatCache[level] = tmp
                return tmp


def lenBurger(level):
    if level == 0:
        return 1
    else:
        if level in lenBurgerCache:
            return lenBurgerCache[level]
        else:
            tmp = 3 + lenBurger(level - 1) * 2
            lenBurgerCache[level] = tmp
            return tmp


str = input().split()
n = int(str[0])
x = int(str[1])

print(nOfPatty(n, x))


Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
n,x=map(int,input().split())

def makeBurger(n):
    if n==1:
        return 'bpppb'
    else:
        burger=makeBurger(n-1)
        print(n)
        return 'b'+burger+'p'+burger+'b'

burger=makeBurger(n)
cnt=0
for i in range(x):
    if burger[i]=='p':
        cnt+=1
print(cnt)

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

def makeBurger(n):
    if n==1:
        return [1,3,1]
    else:
        burger=makeBurger(n-1)
        newBurger=[*burger,1,*burger]
        newBurger[0]+=1
        newBurger[-1]+=1
        print(newBurger)
        return newBurger

burger=makeBurger(n)
size=0
index=0
cnt=0
while size<=x:
    layerSize=burger[index]
    if index%2:
        if size+layerSize>x:
            cnt+=x-size
            break
        else:
            cnt+=layerSize
    size+=layerSize
    index+=1
print(cnt)

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

thickness=[1]
for i in range(1,n):
    thickness.append(2*thickness[i-1]+3)
patty=[1]
for i in range(1,n):
    patty.append(2*patty[i-1]+1)


def pattyCnt(n,x):
    if n==0:
        return 0 if x<=0 else 1
    elif x<=1+thickness[n-1]:
        return pattyCnt(n-1,x-1)
    else:
        return patty[n-1]+1+pattyCnt(n-1,x-2-thickness[n-1])

print(pattyCnt(n,x))

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
N, X = (int(i) for i in input().split())  
L = [1]
P = [1]

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

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

#print(L,P)
print(count(X, N))

N, X = (int(i) for i in input().split())  
L = [1]
P = [1]

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

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

#print(L,P)
print(count(X, N))

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
n, x = map(int,input().split())
def ABC115D(n,x):
    if n == 0:
        return 1
    elif x == 1:
        return 0
    elif x >= 2**(n+1)-1:
        return ABC115D(n-1,x-2**(n+1)+1) + 2**n
    else:
        return ABC115D(n-1,x-1)
print(ABC115D(n,x))

n, x = map(int,input().split())
def ABC115D(n,x):
    if x == 1:
        return 0
    elif n == 0:
        return 1
    elif x >= 2**(n+1)-1:
        return ABC115D(n-1,x-2**(n+1)+1) + 2**n
    elif x == 2**(n+1)-2:
        return 2**n - 1
    else:
        return ABC115D(n-1,x-1)
print(ABC115D(n,x))

n, x = map(int,input().split())
def ABC115D(n,x):
    if n == 0:
        return 1
    elif x == 1:
        return 0
    elif x >= 2**(n+1)-1:
        return ABC115D(n-1,x-2**(n+1)+1) + 2**n
    elif x == 2**(n+1)-2:
        return 2**n - 1
    else:
        return ABC115D(n-1,x-1)
print(ABC115D(n,x))

n, x = map(int,input().split())
def ABC115D(n,x):
    if x == 0:
        return 0
    if n == 0:
        return 1
    elif x == 1:
        return 0
    elif x >= 2**(n+1)-1:
        return ABC115D(n-1,x-2**(n+1)+1) + 2**n
    else:
        return ABC115D(n-1,x-1)
print(ABC115D(n,x))

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
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))

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

Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
n, k = list(map(int, input().split(' ')))
lens = {0: 1}
for i in range(1, 51):
  lens[i] = lens[i-1] * 2 + 3
memo = {}

def sumP(level, index):
  key = (level, index)
  if key in memo:
    return memo[key]
  if level == 0:
      memo[key] = int(index == 1)
  elif index < lens[level] // 2 + 1:   
    memo[key] = sumP(level-1, index-1)
  elif index <= lens[level] // 2 + 1:  
    memo[key] =  + sumP(level-1, lens[level-1])
  else:                                
    memo[key] = sumP(level-1, lens[level-1]) + 1 + sumP(level-1, min(lens[level-1], index-lens[level-1]-2))
  return memo[key]

print(sumP(n, k))

  

n, k = list(map(int, input().split(' ')))
lens = {0: 1}
for i in range(1, 51):
  lens[i] = lens[i-1] * 2 + 3

memo = {}
def sumP(level, index):
  key = (level, index)
  if key in memo:
    return memo[key]
  if level == 0:                       # |P or P|
      memo[key] = int(index == 1)
  elif index < lens[level] // 2 + 1:   
    memo[key] = sumP(level-1, index-1)
  elif index <= lens[level] // 2 + 1:  
    memo[key] = 1 + sumP(level-1, lens[level-1])
  else:                                
    memo[key] = sumP(level-1, lens[level-1]) + 1 + sumP(level-1, min(lens[level-1], index-lens[level-1]-2))
  return memo[key]

print(sumP(n, k))

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
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
    elif X == 0:
        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))



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



Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
n, eat = map(int, input().split())

pattiesCount = lambda level: (1 << (level + 1)) - 1
bunsCount = lambda level: (1 << (level + 1)) - 2
bothCount = lambda level: (1 << (level + 2)) - 3






def doit(level, eat):
    if level == 0:
        return int(eat == 1)
    both = bothCount(level)
    patties = pattiesCount(level)
    if eat == both + 2:
        return 1 + patties
    if eat > both + 1:
        return 1 + patties + doit(level - 1, eat - 2 - both)
    return doit(level - 1, eat - 1)

print(doit(n, eat))


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

pattiesCount = lambda level: (1 << (level + 1)) - 1
bunsCount = lambda level: (1 << (level + 1)) - 2
bothCount = lambda level: (1 << (level + 2)) - 3






def doit(level, eat):
    if level == 0:
        return int(eat >= 1)
    both = bothCount(level - 1)
    patties = pattiesCount(level - 1)
    if eat == both + 2:
        return 1 + patties
    if eat > both + 1:
        return 1 + patties + doit(level - 1, eat - 2 - both)
    return doit(level - 1, eat - 1)

print(doit(n, eat))


Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
import pdb
import sys
sys.setrecursionlimit(10000)

def eat(n, x):
    ret = 0

    if x == 0:
        return 0, x

    if n == 0:
        x -= 1
        return 1, x

    if allnum[n] <= x:
        x -= allnum[n]
        return pnum[n], x
        
    
    x -= 1 # eat bread
    if x == 0:
        return 0, x

    # eat n-1 beager
    tmp, x = eat(n - 1, x)
    ret += tmp
    if x == 0:
        return ret, x

    # eat patty
    x -= 1
    ret += 1
    if x == 0:
        return ret, x

    # eat n-1 beager
    tmp, x = eat(n - 1, x)
    ret += tmp
    if x == 0:
        return ret, x

    x -= 1 # eat bread
        
    return ret, x


def main():
    tmp = input().split()
    n = int(tmp[0])
    x = int(tmp[1])
    global pnum
    global allnum
    pnum = [1]
    allnum = [1]
    for i  in range(1, 52):
        pnum.append(pnum[i-1] * 2 + 1)
        allnum.append(allnum[i-1] * 2 + 3)
    print(len(pnum))
    print(len(allnum))
    
    ans, tmp = eat(n, x)

    print("%d" % ans)

        
if __name__ == '__main__':
    main()


import pdb

def eat(n, x):
    ret = 0

    if x == 0:
        return 0, x

    if n == 0:
        x -= 1
        return 1, x

    if allnum[n] <= x:
        x -= allnum[n]
        return pnum[n], x
        
    # eat bread
    x -= 1 
    if x == 0:
        return 0, x

    # eat n-1 beager
    tmp, x = eat(n - 1, x)
    ret += tmp
    if x == 0:
        return ret, x

    # eat patty
    x -= 1
    ret += 1
    if x == 0:
        return ret, x

    # eat n-1 beager
    tmp, x = eat(n - 1, x)
    ret += tmp
    if x == 0:
        return ret, x

    # eat bread
    x -= 1 
        
    return ret, x


def main():
    tmp = input().split()
    n = int(tmp[0])
    x = int(tmp[1])
    global pnum
    global allnum
    pnum = [1]
    allnum = [1]
    for i  in range(1, 51):
        pnum.append(pnum[i-1] * 2 + 1)
        allnum.append(allnum[i-1] * 2 + 3)

    ans, tmp = eat(n, x)

    print(ans)

        
if __name__ == '__main__':
    main()


Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
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

#print(P)
#print(A)

def dfs(n, x):
    if n == 0:
        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))

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

#print(P)
#print(A)
 
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))    

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
import sys
sys.setrecursionlimit(10**5)

def solve(n, x):
  if n == 0:
    if x > 1:
      return 1
    else:
      return 0
  else:
    ans = 0
    burger_prev = 2**(n+1)-3
    pate_prev = 2**n-1
    if x > 1:
      if x < burger_prev+1:
        ans += solve(n-1 ,x-1)
      else:
        ans += pate_prev
        if x > burger_prev+2:
          ans += 1
          if x > burger_prev*2+2:
            ans += pate_prev
          else:
            ans += solve(n-1, x-2-burger_prev)
    return ans

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



import sys
sys.setrecursionlimit(10**5)

def solve(n, x):
  if n == 0:
    if x > 0:
      return 1
    else:
      return 0
  else:
    ans = 0
    burger_prev = 2**(n+1)-3
    pate_prev = 2**n-1
    if x > 1:
      if x < burger_prev+1:
        ans += solve(n-1 ,x-1)
      else:
        ans += pate_prev
        if x > burger_prev+1:
          ans += 1
          if x > burger_prev*2+2:
            ans += pate_prev
          else:
            ans += solve(n-1, x-2-burger_prev)
    return ans

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


Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
N, X = map(int, input().split())
patty = [1]
buns = [0]

for i in range(0, N):
    patty.append(patty[i] * 2 + 1)
    buns.append(buns[i] * 2 + 2)

print(patty)
print(buns)

burger_high = patty[N] + buns[N]
print("burger : ", burger_high)
print("burger/2 : ", burger_high/2)


def dfs(now_runrun, now_burger_high, dimension):
    if dimension == 0:
        return 1
    
    elif now_runrun == 1:
        return 0

    
    elif now_runrun == now_burger_high // 2 + 1:
        return patty[dimension - 1] + 1

    
    elif now_runrun == now_burger_high:
        return patty[dimension]


    next_burger = now_burger_high // 2 - 1
    next_dimension = dimension - 1

    if now_runrun <= now_burger_high // 2:
        return dfs(now_runrun - 1, next_burger, next_dimension)
    else:
        return dfs(now_runrun - (patty[next_dimension] + buns[next_dimension] + 2),
                   next_burger, next_dimension) + patty[next_dimension] + 1


print(dfs(X, burger_high, N))


N, X = map(int, input().split())
pattis = [1]
buns = [0]

for i in range(N):
    pattis.append(pattis[i] * 2 + 1)
    buns.append(buns[i] * 2 + 2)


# print(buns)

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


    
    burger_high = pattis[n] + buns[n]
    if x == 1:
        return 0
    elif x == burger_high:
        return pattis[n - 1] * 2 + 1
    elif x == burger_high // 2 + 1:
        return pattis[n - 1] + 1

    
    if 1 < x <= burger_high // 2:
        return dfs(n - 1, x - 1)
    elif burger_high // 2 < x < burger_high:
        return dfs(n - 1, x - (pattis[n - 1] + buns[n - 1] + 2)) + pattis[n - 1] + 1


print(dfs(N, X))

Verdicts: Wrong Answer

Accepted