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:
import sys
sys.setrecursionlimit(100000000)

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

height=[-1]*51
niku=[-1]*51
height[0]=1
niku[0]=1

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

def rec(l, x):
    if x==0:return 0
    if x < 1+height[l-1]+1:
        return rec(l-1, x-1)
    elif x == 1+height[l-1]+1:
        return 1 + niku[l-1]
    else:
        return niku[l-1] + 1 + rec(l-1, x-height[l-1]-2)
print(rec(N, X))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(100000000)

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

height=[-1]*51
niku=[-1]*51
height[0]=1
niku[0]=1

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

def rec(l, x):
    if x >= height[l]:
        return niku[l]
    if x<=0:return 0
    if x < 1+height[l-1]:
        return rec(l-1, x-1)
    elif x == 1+height[l-1]:
        return 1 + niku[l-1]
    else:
        return niku[l-1] + 1 + rec(l-1, x-height[l-1]-2)
print(rec(N, X))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(100000000)

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

height=[-1]*51
niku=[-1]*51
height[0]=1
niku[0]=1

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

def rec(l, x):
    if x >= height[l]:
        return niku[l]
    if x<=0:return 0
    if x < 1+height[l-1]:
        return rec(l-1, x-1)
    else:
        return niku[l-1]+1 + rec(l-1, x-height[l-1]-2)
print(rec(N, X))

Submission status: Wrong Answer

Solution code:

ans = 0
def count_ans(level, index, len_dic, p_dic):
    global ans
    if level == 0:
        if index == 0:
            ans += 1
    elif index == 0:
        pass
    else:
        if index == len_dic[level] // 2:
            ans += 1
            ans += p_dic[level - 1]
        elif index > len_dic[level] // 2:
            ans += p_dic[level - 1] + 1
            index_next = index - len_dic[level - 1] - 2
            count_ans(level - 1, index_next, len_dic, p_dic)
        else:
            index_next = index - 1
            count_ans(level - 1, index_next, len_dic, p_dic)


def get_len_dic(level):
    len_dic = [1]
    for i in range(level):
        len_dic.append(len_dic[-1] * 2 + 3)
    return len_dic

def get_p_dic(level):
    p_dic = [1]
    for i in range(level - 1):
        p_dic.append(p_dic[-1] * 2 + 1)
    return p_dic

def main():
    global ans
    level, eat_num = map(int, input().split())
    len_dic = get_len_dic(level)
    p_dic = get_p_dic(level)
    count_ans(level, eat_num - 1, len_dic, p_dic)
    print(ans)





if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:

ans = 0
def count_ans(level, index, len_dic, p_dic):
    global ans

    if level == 0:
        if index == 0:
            ans += 1
    elif index == 0:
        pass
    else:
        if index == len_dic[level - 1] // 2 + 1:
            ans += 1
            ans += p_dic[level - 1]
        elif index > len_dic[level] // 2 + 1:
            ans += p_dic[level - 1] + 1
            index_next = index - len_dic[level - 1] - 2
            count_ans(level - 1, index_next, len_dic, p_dic)
        else:
            index_next = index - 1
            count_ans(level - 1, index_next, len_dic, p_dic)


def get_len_dic(level):
    len_dic = [1]
    for i in range(level):
        len_dic.append(len_dic[-1] * 2 + 3)
    return len_dic

def get_p_dic(level):
    p_dic = [1]
    for i in range(level - 1):
        p_dic.append(p_dic[-1] * 2 + 1)
    return p_dic

def main():
    global ans
    level, eat_num = map(int, input().split())
    len_dic = get_len_dic(level)
    p_dic = get_p_dic(level)
    count_ans(level, eat_num, len_dic, p_dic)
    print(ans)





if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float('inf')
MOD = 10**9+7
dy = [0,1,0,-1]
dx = [1,0,-1,0]
ddy = [0,1,1,1,0,-1,-1,-1]
ddx = [1,1,0,-1,-1,-1,0,1]

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

def f(N,X):
    if N == 0:
        return 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,x))

Submission status: Wrong Answer

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

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

print(pati(N, X))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys


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


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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

print(f(N,X))

Submission status: Wrong Answer

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

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

print(f(N,X))

Submission status: Wrong Answer

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

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

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

    else:
        return lenputty[level]

print(burger(N, X))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

Solution code:
# B-R()-P-R()-B

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

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

# layer k, rest x
def f(k, x):
    ret = 0

    # 一番左の B を食べる
    if x <= 1:
        return ret
    x -= 1

    # L-1 を食べる
    # 枚数は分かっている (total, psum) ので全部食べられるならそれを使って終わり
    # 切れ目が途中にある場合は再帰呼び出し
    if x <= total[k - 1]:
        return ret + f(k - 1, x)
    ret += psum[k - 1]
    x -= total[k - 1]

    # 真ん中の P を食べる
    if x < 1:
        return ret
    ret += 1
    x -= 1

    # 2回目の L-1 を食べる
    if x <= total[k - 1]:
        return ret + f(k - 1, x)
    ret += psum[k - 1]
    x -= total[k - 1]

    # 最後の B を食べる (残り 0 or 1 でないと何かがおかしい)
    assert x <= 1
    return ret

print(f(N, X))

Submission status: Wrong Answer

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

#A
def A():
    return

#B
def B():
    return

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


    
    return

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


#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    D()

Submission status: Wrong Answer

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

#A
def A():
    return

#B
def B():
    return

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


    
    return

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


#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    D()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

#print(P)
#print(B)
#print(A)

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

print(dfs(n, x))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

print(f(N, X))

Submission status: Wrong Answer

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

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

print(f(N, X))

Submission status: Wrong Answer

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

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

print(f(N, X))

Submission status: Wrong Answer

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

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

print(f(N, X))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:

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


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


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

    ai = a(N)
    if X < ai // 2 + 1:
        # レベルN-1バーガーに含まれる。
        return f(N-1, X-1)
    if X == ai // 2 + 1:
        # 中央のパティ + レベルN-1バーガーに含まれる全てのパティ
        return 1 + p(N-1)
    # レベルN-1バーガの全てのパティ + 中央のパティ
    # + レベルN-1バーガの下から(X-(ai+2))そうに含まれるパティ
    return 1 + p(N-1) + f(N-1, X-(ai + 2))


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

Submission status: Wrong Answer

Solution code:

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


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


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

    ai = a(N)
    if X == 1:
        # 一番下のパンだけ
        return 0
    if X < ai // 2 + 1:
        # レベルN-1バーガーに含まれる。
        return f(N-1, X-1)
    if X == ai // 2 + 1:
        # 中央のパティ + レベルN-1バーガーに含まれる全てのパティ
        return 1 + p(N-1)
    if X < ai:
        # レベルN-1バーガの全てのパティ + 中央のパティ
        # + レベルN-1バーガの下から(X-(ai+2))そうに含まれるパティ
        return 1 + p(N-1) + f(N-1, X-(ai + 2))

    # X == ai つまりはレベルNバーガの全体
    return p(N)


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

Submission status: Wrong Answer

Solution code:

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


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


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

    ai = a(N)
    if X == 1:
        # 一番下のパンだけ
        return 0
    if X < ai // 2:
        # レベルN-1バーガーに含まれる。
        return f(N-1, X-1)
    if X == ai // 2 + 1:
        # 中央のパティ + レベルN-1バーガーに含まれる全てのパティ
        return 1 + p(N-1)
    if X < ai:
        # レベルN-1バーガの全てのパティ + 中央のパティ
        # + レベルN-1バーガの下から(X-(ai+2))そうに含まれるパティ
        return 1 + p(N-1) + f(N-1, X-(ai + 2))

    # X == ai つまりはレベルNバーガの全体
    return p(N)


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

Submission status: Wrong Answer

Solution code:

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


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


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

    ai = a(N)
    if X == 1:
        # 一番下のパンだけ
        return 0
    if X < ai // 2:
        # レベルN-1バーガーに含まれる。
        return f(N-1, X-1)
    if X == ai // 2 + 1:
        # 中央のパティ + レベルN-1バーガーに含まれる全てのパティ
        return 1 + p(N-1)
    if X < ai:
        # レベルN-1バーガの全てのパティ + 中央のパティ
        # + レベルN-1バーガの下から(X-(ai+2))そうに含まれるパティ
        return 1 + p(N-1) + f(N, X-(ai + 2))

    # X == ai つまりはレベルNバーガの全体
    return p(N)


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

Submission status: Wrong Answer

Solution code:

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


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


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

    ai = a(N-1)
    if X == 1:
        # 一番下のパンだけ
        return 0
    if X < ai + 2:
        # レベルN-1バーガーに含まれる。
        return f(N-1, X-1)
    if X == ai + 2:
        # 中央のパティ + レベルN-1バーガーに含まれる全てのパティ
        return 1 + p(N-1)
    if X < 2*ai + 3:
        # レベルN-1バーガの全てのパティ + 中央のパティ
        # + レベルN-1バーガの下から(X-(ai+2))そうに含まれるパティ
        return 1 + p(N-1) + f(N, X-(ai + 2))

    # X == 2*ai + 3 つまりはレベルNバーガの全体
    return p(N)


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

Submission status: Wrong Answer

Solution code:

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


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


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

    ai = a(N-1)
    if X == 1:
        # 一番下のパンだけ
        return 0
    if X < ai + 2:
        # レベルN-1バーガーに含まれる。
        return f(N-1, X-1)
    if X == ai + 2:
        # 中央のパティ + レベルN-1バーガーに含まれる全てのパティ
        return 1 + p(N-1)
    if X < 2*ai + 3:
        # レベルN-1バーガの全てのパティ + 中央のパティ
        # + レベルN-1バーガの下から(X-(ai+2))そうに含まれるパティ
        return 1 + p(N-1) + f(N, X-(ai + 2))
    # X == 2*ai + 3 つまりはレベルNバーガの全体
    return p(N)


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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools


sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]


def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    global a, p
    #  N, X = LI()
    N = 50
    X = 4321098765432109
    a, p = [1], [1]
    for i in range(N):
        a.append(a[i] * 2 + 3)
        p.append(p[i] * 2 + 1)
    print(make_burger(N, X))
    return


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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))

N,X=rl()

p = [0]*(N+1)
l = [0]*(N+1)
p[0]=1
l[0]=1

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


ans = 0

for i in range(N-1,-1,-1):
    if X==1:
        X -= 1
        break
    elif X <= 1+l[i]:
        X -= 1
    elif X == 1+l[i]+1:
        X -= 1+l[i]+1
        ans += p[i]+1
        break
    elif X <= 2+2*l[i]:
        X -= 2+l[i]
        ans += p[i]+1
    else:
        X -= 3+2*l[i]
        ans += 2*p[i]+1
        break
print(ans)

Submission status: Wrong Answer

Solution code:
N,X=map(int,input().split())
H=[1]
P=[1]

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

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