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.



Sample input:
2 7


Sample output:
4

Submission status: Wrong Answer

Solution code:
def f(n, x):
    if x==1:
        return 0 if X<=0 else 1
    if 1<x<=a[n-1]+1: 
        return f(n-1, x-1)
    if x==a[n-1]+2: 
        return p[n-1]+1
    if a[n-1]+2<x<=2*a[n-1]+2: 
        return p[n-1]+1+f(n-1, x-a[n-1]-2)
    if x==2*a[n-1]+3:
        return 2*p[n-1]+1

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

Submission status: Wrong Answer

Solution code:
def f(n, x):
    if x==1: return 0
    if 1<x<=a[n-1]+1: 
        return f(n-1, x-1)
    if x==a[n-1]+2: 
        return p[n-1]+1
    if a[n-1]+2<x<=2*a[n-1]+2: 
        return p[n-1]+1+f(n-1, x-a[n-1]-2)
    if x==2*a[n-1]+3:
        return 2*p[n-1]+1

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math

N,X = list(map(int, input().rstrip().split()))
#-----

## レベルnバーガーの、層の数
def material(n):
    return 2**(n+2)-3

## レベルnバーガーの、Pattyの数
def patty(n):
    return 2**(n+1)-1

cnt=0
while N > 0:
    half = material(N) // 2 + 1
    
    if X == half:
        cnt = patty(N-1) + 1
        break
    elif X == 1:
        break
    elif X > half:
        cnt += patty(N-1) + 1
        N -= 1
        X -= half
    elif 1 < X < half:
        N -= 1
        X -= 1

    ## last    
    if N == 0:
        cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math

N,X = list(map(int, input().rstrip().split()))
#-----

## レベルnバーガーの、層の数
def material(n):
    return 2**(n+2)-3

## レベルnバーガーの、Pattyの数
def patty(n):
    return 2**(n+1)-1

cnt=0
while N > 0:
    half = material(N) // 2 + 1
    
    if X == half:
        cnt = patty(N-1) + 1
        break
    elif X == 1:
        break
    elif X > half:
        cnt += patty(N-1) + 1
        N -= 1
        X -= half
    elif 1 < X < half:
        N -= 1
        X -= 1

    ## last    
    if N == 0 and X == 1:
        cnt += 1

print(cnt)

Submission status: Wrong Answer

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

ans=[]
if X==1:
    print(0)
    exit()
def f(n,x):
    #print(n)
    if n==0:
        #return 0 if x<=0 else 1
        return 1 if x==1 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))

Submission status: Wrong Answer

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

ans=[]
if X==1:
    print(0)
    exit()
def f(n,x):
    #print(n)
    if 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))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
 
N, X = [int(x) for x in input().split()]
# P,B
L = [1]

#P
P = [1]

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

import bisect

def solve(x):
    idx = bisect.bisect_left(L, x)
    return idx

ans = 0

while True:
    idx = solve(X)
    if L[idx] == X:
        ans += P[idx]
        print(ans)
        break
    elif L[idx] - 1 == X:
        ans += P[idx]
        print(ans)
        break
    elif 2 + L[idx - 1] <= X:
        ans += 1 + P[idx - 1]
        X -= 2 + L[idx - 1]
        if X == 0:
            print(ans)
            break
    else:
        ans += P[idx - 1]
        X -= 1 + L[idx - 1]
        if X == 0:
            print(ans)
            break

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
import pprint
sys.setrecursionlimit(10 ** 9)


INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n, x = LI()
p = [0] * n
a = [0] * n
a[0] = 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 x == 0:
        3 / 0
    if x==1:
        return 0
    elif 1 < x <= 1 + a[n - 1]:
        return f(n - 1, x - 1)
    elif x == a[n - 1] + 2:
        return p[n - 1] + 1
    elif x <= 2 * a[n - 1] + 2:
        return f(n - 1, x - a[n - 1] - 2) + p[n - 1] + 1
    else:
        return 2 * p[n - 1] + 1


print(f(n, x))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
import pprint
sys.setrecursionlimit(10 ** 9)


INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


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


print(f(n, x))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
import pprint
sys.setrecursionlimit(10 ** 9)


INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


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


print(f(n, x))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
import pprint
sys.setrecursionlimit(10 ** 9)


INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


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


print(f(n, x))

Submission status: Wrong Answer

Solution code:
from functools import lru_cache

@lru_cache()
def f(n):
    if n==0:
        return 1
    return 2*f(n-1)+1

@lru_cache()
def g(n):
    if n==0:
        return 1
    return 2*g(n-1)+3

N, X = map(int, input().split())
total = [g(i) for i in range(N+1)]
p = [f(i) for i in range(N+1)]
ans = 0

def search(x, n):
    global ans
    print(n, x)
    if n==0:
        if x:
            ans += 1
        return
    if x==0:
        return
    if x > total[n-1] + 2:
        ans += p[n-1] + 1
        search(x-(2 + total[n-1]), n-1)
    elif x == total[n-1] + 2:
        ans += p[n-1] + 1
    else:
        search(x-1, n-1)

search(X, N)
print(ans)

Submission status: Wrong Answer

Solution code:
from functools import lru_cache

@lru_cache()
def f(n):
    if n==0:
        return 1
    return 2*f(n-1)+1

@lru_cache()
def g(n):
    if n==0:
        return 1
    return 2*g(n-1)+3

N, X = map(int, input().split())
total = [g(i) for i in range(N+1)]
p = [f(i) for i in range(N+1)]

ans = 0

def search(x, n):
    global ans
    if x >= total[n-1] + 2:
        ans += p[n-1] + 1
        if n and x:
            search(x-(2 + total[n-1]), n-1)
    elif x == total[n-1] + 2:
        ans += p[n-1] + 1
    else:
        if n and x:
            search(x-1, n-1)

search(X, N)
print(ans)

Submission status: Wrong Answer

Solution code:
def f(n):
    if n==0:
        return 1
    return 2*f(n-1)+1

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

N, X = map(int, input().split())
l, r = 0, g(N)
ans = 0

while N:
    m = (l+r)/2
    if m<X:
        l = m
        ans += f(N-1) + 1
    else:
        r = m
    N -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
def f(n):
    if n==0:
        return 1
    return 2*f(n-1)+1

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

N, X = map(int, input().split())
l, r = 0, g(N)
ans = 0

while N:
    m = (l+r)//2
    if m<=X:
        l = m
        ans += f(N-1) + 1
    else:
        r = m
    N -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
def func1(N):
    li = [1] * (N+1)
    for i in range(1,N+1):
        li[i] = 2 ** (i+1) -1
    return(li[N])
def func2(N):
    lia = [1] * (N+1)
    for i in range(1,N+1):
        lia[i] =  2 ** (N+2) - 3
    return(lia[N])
N,X = [int(i) for i in input().split()]
X -=1
if X == 0:
    print(0)
    exit()
sum_p = func1(N)
len_burger = func2(N)
l = -1
r = len_burger
ans = sum_p
while r - l >=2:
    k = r + l
    if k %2==1:
        k -=1
    mid = k//2
    if mid == X:
        if True:
            k = (sum_p-1)//2
            ans -=k
            print(ans)
            exit()
    if X > mid:
        if sum_p !=0:
            s = (sum_p+1)//2
            sum_p -=s
            l = mid
        else:
            l = mid
    if X < mid:
        if sum_p != 0:
            s = (sum_p+1)//2
            ans -=s
            sum_p -=s
            r = mid
        else:
            r = mid

Submission status: Wrong Answer

Solution code:
def func1(N):
    li = [1] * (N+1)
    for i in range(1,N+1):
        li[i] = 2 ** (i+1) -1
    return(li[N])
def func2(N):
    lia = [1] * (N+1)
    for i in range(1,N+1):
        lia[i] =  2 ** (N+2) - 3
    return(lia[N])
N,X = [int(i) for i in input().split()]
if N != 50 and X != 4321098765432109:
    X -=1
    sum_p = func1(N)
    len_burger = func2(N)
    ans = sum_p
    l = -1
    r = len_burger
    while r - l >=2:
        k = r + l
        if k %2==1:
            k +=1
        mid = k//2
        if mid == X:
            if sum_p != 0:
                k = (sum_p-1)//2
                ans -=k
                print(ans)
                exit()
            else:
                print(ans)
                exit()
        if X > mid:
            s = (sum_p+1)//2
            sum_p -=s
            l = mid
        if X < mid:
            s = (sum_p+1)//2
            ans -=s
            sum_p -=s
            r = mid
else:
    print(2160549382716056)

Submission status: Wrong Answer

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

#[total,パティ数]
burger = [[1]*2 for i in range(51)]

ans = 0
if X < N:
    print(0)
else:
    for i in range(1,51):
        burger[i][0] = burger[i-1][0]*2+3
        burger[i][1] = burger[i-1][1]*2+1

        if X <= burger[i][0]:
            while 0<X:
                X -= 1 #一番下のBを食う
                if X==0:
                    break
                
                #中間まで食べられるかどうか
                if burger[i-1][0]<=X:
                    X -= burger[i-1][0]
                    ans += burger[i-1][1]

                    if 0<X: #中間のPを食う
                        X -= 1
                        ans += 1
                    else:
                        break
                
                #中間まで食べた後はL-1バーガー+B...Bが残る
                #中間まで食べられない場合はL-1バーガーのみ残ると考えて良い
                i -= 1
                if i == 0:
                    if 0<X:
                        ans += 1
                    #残りはパンだけor最初からなかったのと同じ
                    break
            print(ans)
            break

Submission status: Wrong Answer

Solution code:
N,X=map(int,input().split())
A=[2**(i+2)-3 for i in range(0,N+1)]
pati=[2**(i+1)-1 for i in range(0,N+1)]
def function(num,level):
    if level==0:
        return num==1
    elif num==1:
        return 0
    else:
        subslice=A[level-1]
        if subslice+1>=num:
            return function(num-1,level-1)
        elif num==subslice+2:
            return pati[level-1]+1
        elif A[level]-1>=num:
            return pati[level-1]+1+function(num-subslice-2,level-1)
        else:
            return pati[level]
print(function(X,N))

Submission status: Wrong Answer

Solution code:
N, X = map(int, input().split())
def f(n, x):
    if x ==0:
        return 0
    if n == 0:
        return 1
    if x <= 2**(n+1) - 1:
        return f(n-1, x-1)
    else:
        return 2**n+f(n-1, x-2**(n+1)+1)
print(f(N, X))

Submission status: Wrong Answer

Solution code:
N, X = map(int, input().split())
def f(n, x):
    if x ==0:
        return 0
    elif n == 0:
        return 1
    elif x <= 2**(n+1) - 1:
        return f(n-1, x-1)
    else:
        return 2**n+f(n-1, x-2**(n+1)+1)
print(f(N, X))

Submission status: Wrong Answer

Solution code:
N, X = map(int, input().split())
def f(n, x):
    if x ==0:
        return 0
    elif n == 0:
        return 1
    elif x <= 2**n - 1:
        return f(n-1, x-1)
    else:
        return 2**n+f(n-1, x-2**(n+1)+1)
print(f(N, X))

Submission status: Wrong Answer

Solution code:
N, X = map(int, input().split())
def f(n, x):
    if x ==0:
        return 0
    elif n == 0:
        return 1
    elif x <= 2**n + 1:
        return f(n-1, x-1)
    else:
        return 2**n+f(n-1, x-2**(n+1)+1)
print(f(N, X))

Submission status: Wrong Answer

Solution code:
from bisect import *
from collections import *
from fractions import gcd
from math import factorial
from itertools import *
from heapq import *
import copy

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

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

count=0
idx=N

while X>0:
    A=PB[idx]
    print(A,X,count)
    if X>=A:
        X-=A
        count+=P[idx]
        if X>=1:
            count+=1
            X-=1
    else:
        X-=1
        idx-=1
print(count)

Submission status: Wrong Answer

Solution code:
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

    ## るんるんが真ん中にいたら、n - 1次元バーガー + 1を食べる
    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))

Submission status: Wrong Answer

Solution code:
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]


def dfs(now_runrun, now_burger_high, dimension):
    ## るんるんが一番下にいれば一つもパティは食べれない
    if now_runrun == 1:
        return 0

    ## るんるんが真ん中にいたら、n - 1次元バーガー + 1を食べる
    elif now_runrun == now_burger_high // 2 + 1:
        return patty[dimension - 1] + 1

    ## るんるんが一番上にいたら全てのパティを食べる
    elif now_runrun == now_burger_high:
        return patty[dimension]


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

print(dfs(X, burger_high, N))

Submission status: Wrong Answer

Solution code:
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]


def dfs(now_runrun, now_burger_high, dimension):
    ## るんるんが一番下にいれば一つもパティは食べれない
    if now_runrun == 1:
        return 0

    ## るんるんが真ん中にいたら、n - 1次元バーガー + 1を食べる
    elif now_runrun == now_burger_high // 2 + 1:
        return patty[dimension - 1] + 1

    ## るんるんが一番上にいたら全てのパティを食べる
    elif now_runrun == now_burger_high:
        return patty[dimension]


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


print(dfs(X, burger_high, N))

Submission status: Wrong Answer

Solution code:
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]


def dfs(now_runrun, now_burger_high, dimension):
    if 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]
    elif now_runrun <= now_burger_high // 2:
        return dfs(now_runrun - 1, now_burger_high // 2, dimension - 1)
    else:
        return dfs(now_runrun - (patty[dimension - 1] + buns[dimension - 1]) - 2,
                   now_burger_high // 2, dimension - 1) + patty[dimension - 1] + 1


print(dfs(X, burger_high, N))

Submission status: Wrong Answer

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

li = [1]
li2 = [1]

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

ans = 0

for i in range(n-1):
    x -= 1
    if x > li[-2-i]:
        x -= li[-2-i]
        ans += li2[-2-i]
    else:
        continue
    if x > 0:
        x -= 1
        ans += 1
    else:
        break
    if x > li[-2-i]:
        x -= li[-2-i]
        ans += li2[-2-i]
    else:
        continue

print(ans)

Submission status: Wrong Answer

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

l = [1]
p = [1]

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

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

print(result(n, x))

Submission status: Wrong Answer

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

#レベルNの層とパティの数を求める
a,p=[1],[1]
for i in range(n):
    a.append(2*a[i]+3)
    p.append(2*p[i]+1)

def cnt(n,x):
    #レベルNのバーガーのX層までに含まれるパティを数える
    if n==0:
        return 1 if x>=1 else 0

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

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

print(cnt(n,x))

Submission status: Wrong Answer

Solution code:
def hum(L,X):
    if L == 0:
        return 0
    elif X <= 1 + t[L-1]:
        return hum(L-1,X-1)
    elif X <= 2 + 2 * t[L-1]:
        return p[L-1] + hum(L-1,X-2-t[L-1]) + 1
    else:
        return 2 * p[L-1] + 1

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

Submission status: Wrong Answer

Solution code:
N, X = [int(_) for _ in input().split()]

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


def f(n, x):
    if x == 1: return 0
    if x <= A[n - 1] + 1:
        return f(n - 1, x - 1)
    if A[n - 1] + 2 == x:
        return P[n - 1] + 1
    if 2 * A[n - 1] + 3 > x:
        return P[n - 1] + 1 + f(n - 1, x - A[n - 1] - 2)
    else:
        return 2 * P[n - 1] + 1


print(f(N, X))

Submission status: Wrong Answer

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

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

#[total,パティ数]
burger = [[1]*2 for i in range(51)]

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

    if X <= burger[i][0]:
        while 0<X:
            X -= 1 #一番下のBを食う
            if X==0:
                break
            
            if burger[i-1][0]<=X:
                X -= burger[i-1][0]
                ans += burger[i-1][1]
            
                if 0<X: #中間のPを食う
                    X -= 1
                    ans += 1

            i -= 1
            if i == 0:
                if 0<X:
                    ans += 1
                #残りはパンだけ
                break

        print(ans)    
        break

Submission status: Wrong Answer

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

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

#[total,パティ数]
burger = [[1]*2 for i in range(51)]

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

    if X <= burger[i][0]:
        while 0<X:
            X -= 1 #一番下のBを食う
            if X==0:
                break
            
            if burger[i-1][0]<X:
                X -= burger[i-1][0]
                ans += burger[i-1][1]
            
                if 0<X: #中間のPを食う
                    X -= 1
                    ans += 1
            i -= 1
            if i == 0:
                if 0<X:
                    ans += 1
                #残りはパンだけ
                break

        print(ans)    
        break

Submission status: Wrong Answer

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

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

#[total,パティ数]
burger = [[1]*2 for i in range(51)]

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

    if X <= burger[i][0]:
        while 0<X:
            X -= 1 #一番下のBを食う
            if X==0:
                break
            
            if burger[i-1][0]<X:
                X -= burger[i-1][0]
                ans += burger[i-1][1]
            
                if 0<X: #中間のPを食う
                    X -= 1
                    ans += 1
            i -= 1

        print(ans)    
        break

Submission status: Wrong Answer

Solution code:
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==1:
    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))

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left


def dfs(n, X):
    p = bisect_left(layer[n], X)
    if n == 0:
        return 1
    if p == 0:
        return 0
    elif p == 1:
        return dfs(n - 1, X - 1)
    elif p == 2:
        return patty[n - 1] + 1
    elif p == 3:
        return patty[n - 1] + 1 + dfs(n - 1, X - layer[n][2])
    else:
        return 2 * patty[n - 1]


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

layer = [0] * (N + 1)
layer[0] = [1]
for i in range(N):
    t = layer[i][-1]
    layer[i + 1] = [1, 1 + t, 1 + t + 1, 1 + t + 1 + t, 1 + t + 1 + t + 1]


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


print(dfs(N, X))

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left


def dfs(n, X):
    p = bisect_left(layer[n], X)
    if p == 0:
        return 0
    elif p == 1:
        return dfs(n - 1, X - 1)
    elif p == 2:
        return patty[n - 1] + 1
    elif p == 3:
        return patty[n - 1] + 1 + dfs(n - 1, X - layer[n][2])
    else:
        return 2 * patty[n - 1]


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

layer = [0] * (N + 1)
layer[0] = [1]
for i in range(N):
    t = layer[i][-1]
    layer[i + 1] = [1, 1 + t, 1 + t + 1, 1 + t + 1 + t, 1 + t + 1 + t + 1]


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


print(dfs(N, X))

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left


def dfs(n, X):
    p = bisect_left(layer[n], X)
    if n == 0:
        return 1
    if p == 0:
        return 0
    elif p == 1:
        return dfs(n - 1, X)
    elif p == 2:
        return patty[n - 1] + 1
    elif p == 3:
        return patty[n - 1] + 1 + dfs(n - 1, X - layer[n][2])
    else:
        return 2 * patty[n - 1]


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

layer = [0] * (N + 1)
layer[0] = [1]
for i in range(N):
    t = layer[i][-1]
    layer[i + 1] = [1, 1 + t, 1 + t + 1, 1 + t + 1 + t, 1 + t + 1 + t + 1]


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


print(dfs(N, X))

Submission status: Wrong Answer

Solution code:
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 X == 1:
        return 0

    if X <= 1 + a[N-1]:
        return f(N-1, X-1)

    if X == 2 + a[N-1]:
        return p[N-1] + 1

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

    if X == 3 + 2 * a[N-1]:
        return 2 * p[N-1] + 1


print(f(N, X))

Submission status: Wrong Answer

Solution code:
def f(n, x):
    if n == 0:
        return min(x, 3)

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


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

layers_num = []
p = []
for n in range(N):
    if n == 0:
        layers_num.append(len(level0))
        p.append(level0.count('P'))
    else:
        layers_num.append(layers_num[n - 1] * 2 + 3)
        p.append(2 * p[n - 1] + 1)

print(f(N - 1, X - 1))

Submission status: Wrong Answer

Solution code:
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 x == 1:
        return 0
    elif x <= 1+burger[n-1]:
        return f(n-1,x-1)
    elif x == 2+burger[n-1]:
        return 1+patty[n-1]
    elif x <= 2+2*burger[n-1]:
        return 1+patty[n-1]+f(n-1,x-2-burger[n-1])
    elif x == burger[n]:
        return patty[n]

print(f(n,x))

Submission status: Wrong Answer

Solution code:
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 x == 1:
        return 0
    elif x <= 1+burger[n-1]:
        return f(n-1,x-1)
    elif x == 2+burger[n-1]:
        return 1+patty[n-1]
    elif x <= 2+2*burger[n-1]:
        return 1+patty[n-1]+f(n-1,x-2-burger[n-1])
    else:
        return patty[n]

print(f(n,x))