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: Runtime Error

Solution code:
from typing import NamedTuple

class Burger(NamedTuple):
    total: int
    patty: int

def solve(n, x, burgers, total_eaten, patty_eaten):
    if n == 0:
        total_eaten += 1
        patty_eaten += 1
        return total_eaten, patty_eaten

    # try to eat the entire current level
    tmp_total = burgers[n].total
    tmp_patty = burgers[n].patty
    if total_eaten + tmp_total < x:
        return total_eaten + tmp_total, patty_eaten + tmp_patty

    # eat the lower bun
    total_eaten += 1
    if total_eaten == x:
        return total_eaten, patty_eaten

    # eat the lower n - 1 th burger
    total_eaten, patty_eaten = solve(n - 1, x, burgers, total_eaten, patty_eaten)
    if total_eaten == x:
        return total_eaten, patty_eaten

    # eat the middle patty
    total_eaten += 1
    patty_eaten += 1
    if total_eaten == x:
        return total_eaten, patty_eaten

    # eat the upper n - 1 th burger
    total_eaten, patty_eaten = solve(n - 1, x, burgers, total_eaten, patty_eaten)
    if total_eaten == x:
        return total_eaten, patty_eaten

    # eat the upper bun
    # the program should not reach the current line because this mean n th burger is eaten (= eat the entire current level)
    total_eaten += 1
    return total_eaten, patty_eaten

def main():
    N, X = map(int, input().split())
    burgers = [Burger(1, 1)]
    for i in range(N):
        total = burgers[i].total
        patty = burgers[i].patty
        burger = Burger(3 + total*2, 1 + 2*patty)
        burgers.append(burger)
    # print(burgers)
    total_eaten, patty_eaten = 0, 0
    total_eaten, patty_eaten = solve(N, X, burgers, total_eaten, patty_eaten)
    print(patty_eaten)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n, x = map(int, input().split())
l = ["P"]
def lvup(n):
  if n == 0:
    pass
  else:
    lvup(n-1)
    l.append("B"+l[n-1]+"P"+l[n-1]+"B")
lvup(n)
print(l[n][0:x].count("P"))

Submission status: Runtime Error

Solution code:
n, x = map(int, input().split())
l = ["P"]
def lvup(n):
  if n == 0:
    pass
  else:
    lvup(n-1)
    l.append("B"+l[n-1]+"P"+l[n-1]+"B")
print(l[n][0:x].count("P"))

Submission status: Runtime Error

Solution code:
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n, x = ns()
    lim = 51
    total = [int(0) for _ in range(lim)]
    P_total = [int(0) for _ in range(lim)]

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

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

    ans = 0
    base = 1
    L = n
    while base != x:
        if base + total[L] // 2 <= x:
            base += total[L] // 2 + 1
            ans += P_total[L - 1] + 1
            L -= 1
        else:
            base += 1
            L -= 1
            if L == 0:
                ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
N,X=list(map(int,input().split()))
p=[]
a=[]
def search(N):
    if N==0:
        p.append(1)
        a.append(1)
        return 1,1
    else:
        search(N-1)
        p.append(2*p[N-1]+1)
        a.append(2*a[N-1]+3)
search(N)
def bug(N,X):#p,a
    if X==1:return 0
    if 1<X<=1+a[N-1]:
        return bug(N-1,X-1)
    elif X==a[N-1]+2:
        return p[N-1]+1
    elif a[N-1]+2<X<=2+2*a[N-1]:
        return p[N-1]+1+bug(N-1,X-2-a[N-1]-1)
    elif X==3+2*a[N-1]:
        return 2*p[N-1]-1
print(bug(N,X))

Submission status: Runtime Error

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): # X <= 0 や X > a_N を許容し解説本文から簡略化
	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))

Submission status: Runtime Error

Solution code:
N, X = map(int, input().split())
2
3 a, p = [1], [1]
4 for i in range(N):
5 a.append(a[i] * 2 + 3)
6 p.append(p[i] * 2 + 1)
7
8 def f(N, X): # X <= 0 や X > a_N を許容し解説本文から簡略化
9 if N == 0:
10 return 0 if X <= 0 else 1
11 elif X <= 1 + a[N-1]:
12 return f(N-1, X-1)
13 else:
14 return p[N-1] + 1 + f(N-1, X-2-a[N-1])
15
16 print(f(N, X))

Submission status: Runtime Error

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def f(n,x):#レベルnのx番目
    if n==0:return 0 if x<=0 else 1
    if x<=1+A[n-1]:return f(n-1,x-1)
    if x<=2*A[n-1]+2:return 1+P[n-1]+f(n-1,x-A[n-1]-2)
def main():
    n,x=map(int,input().split())
    global A,P
    A=[1, 5, 13, 29, 61, 125, 253, 509, 1021, 2045, 4093, 8189, 16381, 32765, 65533, 131069, 262141, 524285, 1048573, 2097149, 4194301, 8388605, 16777213, 33554429, 67108861, 134217725, 268435453, 536870909, 1073741821, 2147483645, 4294967293, 8589934589, 17179869181, 34359738365, 68719476733, 137438953469, 274877906941, 549755813885, 1099511627773, 2199023255549, 4398046511101, 8796093022205, 17592186044413, 35184372088829, 70368744177661, 140737488355325, 281474976710653, 562949953421309, 1125899906842621, 2251799813685245, 4503599627370493]
    P=[1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535, 131071, 262143, 524287, 1048575, 2097151, 4194303, 8388607, 16777215, 33554431, 67108863, 134217727, 268435455, 536870911, 1073741823, 2147483647, 4294967295, 8589934591, 17179869183, 34359738367, 68719476735, 137438953471, 274877906943, 549755813887, 1099511627775, 2199023255551, 4398046511103, 8796093022207, 17592186044415, 35184372088831, 70368744177663, 140737488355327, 281474976710655, 562949953421311, 1125899906842623, 2251799813685247]
    print(f(n,x))

if __name__=='__main__':
    main()

Submission status: Runtime Error

Solution code:
n,x = map(int,input().split())
a_list = [1]
p_list = [1]
for i in range(n):
  a_list.append(a_list[-1] * 2 + 3)
  p_list.append(p_list[-1] * 2 + 1)
def dfs(n,x):
  if x == 1:
    return 0
  if n == 1:
    if x ==2:
      return 1
    if x == 3 :
      return 2
    if x == 4 or x == 5:
      return 3
  elif 1 < x  and x <= a_list[n-1] +1:
    return dfs(n-1,x-1)
  elif x == a_list[n-1] + 2:
    return p_list[n-1] + 1
  elif a_list[n-1] + 2 < x and x <= 2 * a_list[n-1] + 2:
    return p_list[n-1] + 1 + dfs(n-1,x - (a_list[n-1] + 2))
  elif x == 2 * a_list[i-1] + 3:
    return 2 * p_list[n-1] + 1

print(dfs(n,x))

Submission status: Runtime Error

Solution code:
n,x = map(int,input().split())
a_list = [1]
p_list = [1]
for i in range(n):
  a_list.append(a_list[-1] * 2 + 3)
  p_list.append(p_list[-1] * 2 + 1)
def dfs(n,x):
  if x == 1:
    return 0
  elif 1 < x  and x <= a_list[n-1] +1:
    return dfs(n-1,x-1)
  elif x == a_list[n-1] + 2:
    return p_list[n-1] + 1
  elif a_list[n-1] + 2 < x and x <= 2 * a_list[n-1] + 2:
    return p_list[n-1] + 1 + dfs(n-1,x - (a_list[n-1] + 2))
  elif x == 2 * a_list[i-1] + 3:
    return 2 * p_list[n-1] + 1

print(dfs(n,x))

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**9) #追加

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

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

def f2(n):
	if n == 0:
		return 'P'
	return 'B' + f2(n-1) + 'P' + f2(n-1) + 'B'

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

num = f(n)

ans = 0
while True:
	if num < 10 ** 5:
		break
	tmp = num // 2 + 1

	if x > tmp:
		ans += p(n) // 2 + 1
		x -= tmp
		num -= tmp + 1
	elif x < tmp:
		num -= tmp + 1
		x -= 1
	else:
		print(p(n-1)+1)
		sys.exit()
	n -= 1

string = f2(n)

for i in range(x):
	if string[i] == 'P':
		ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
import sys

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

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

def f2(n):
	if n == 0:
		return 'P'
	return 'B' + f2(n-1) + 'P' + f2(n-1) + 'B'

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

num = f(n)

ans = 0
while True:
	if num < 10 ** 5:
		break
	tmp = num // 2 + 1

	if x > tmp:
		ans += p(n) // 2 + 1
		x -= tmp
		num -= tmp + 1
	elif x < tmp:
		num -= tmp + 1
		x -= 1
	else:
		print(p(n-1)+1)
		sys.exit()
	n -= 1

string = f2(n)

for i in range(x):
	if string[i] == 'P':
		ans += 1
print(ans)

Submission status: Runtime Error

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

def func(n):
    if(n == 0):
        return "P"
    
    n_b = func(n-1)
    barger = "B"+n_b+"P"+n_b+"B"
    
    return barger

n = func(N)
print(n[::-1][:X].count("P"))

Submission status: Runtime Error

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

layer_size = [1]
P_cnt = [1]

for _ in range(50):
  "[-1]は末尾の要素を取得。layer_sizeで、合計"
  layer_size.append(layer_size[-1]*2+3)

  "[-1]は末尾の要素を取得。P_cntはパティの枚数
  P_cnt.append(P_cnt[-1]*2+1)


def solve(level, x):
  if x == 1:
    return 0 if level > 0 else 1
  l = layer_size[level-1]
  p = P_cnt[level-1]
  if x <= 1+l:
    return solve(level-1, x-1)
  elif x == l+2:
    return p+1
  elif x <= 2*l+2:
    return p+1+solve(level-1, x-l-2)
  else:
    return 2*p+1
  
ans = solve(N, X)
print(ans)

Submission status: Runtime Error

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

layer_size = [1]
P_cnt = [1]

for _ in range(50):
  "[-1]は末尾の要素を取得。layer_sizeで、合計"
  layer_size.append(layer_size[-1]*2+3)

  "[-1]は末尾の要素を取得。P_cntはパティの枚数
  P_cnt.append(P_cnt[-1]*2+1)

print(layer_size)
print(P_cnt)

def solve(level, x):
  if x == 1:
    return 0 if level > 0 else 1
  l = layer_size[level-1]
  p = P_cnt[level-1]
  if x <= 1+l:
    return solve(level-1, x-1)
  elif x == l+2:
    return p+1
  elif x <= 2*l+2:
    return p+1+solve(level-1, x-l-2)
  else:
    return 2*p+1
  
ans = solve(N, X)
print(ans)

Submission status: Runtime Error

Solution code:

N = int(input())
X = int(input())

#     1 2 3 4 5 6 7 8 9 0 1 2 3 4
# L0:     p   p       p   p
# L1:   b   p   b   b   p   b
# L2: b           p           b

def rec(n, x):

    if n==0: return 1  # レベル0ではpが１つ
    if x==1: return 0  

    all = (1<<(n+1)) - 3  # 1つ低レベルの総数
    p = (1<<(n)) - 1  # 1つ低レベルのパティ数
    
    # 今レベルは b + rec(n-1) + p + rec(n-1) + b
    if x <= all + 1: return rec(n-1, x-1)  #  低レベル + 1の大きさであれば今レベルから採るpはなし
    if x == all + 2: return p + 1  # 低レベル + 2の大きさであれば、低レベルのp数 + 今レベルの中間のp１つ
    if x <= all * 2 + 2: return p + 1 + rec(n-1, x-all-2)  # 上2つを通過しているので少なくとも低レベル1つと中間のpは食べている. 後は低レベル２つ目のp数に帰着
    if x == all * 2 + 3: return p * 2 + 1  # 低レベル2つまるごと + 中間のp
    return -1000000

print(rec(N, X))

Submission status: Runtime Error

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

x = '1'
for i in range(N):
    x = '0' + x + '1' + x + '0'

print(x[:X].count('1'))

Submission status: Runtime Error

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

zero = 'P'
one = 'BPPPB'
two = 'B'+ one + 'P' +  'BPPPB' + 'B'

current = one

for i in range(1, N):
    current = 'B'+ current + 'P' +  current + 'B'

eaten = current[:X]
print(eaten.count('P'))

Submission status: Runtime Error

Solution code:
import itertools
from collections import deque
N, X = map(int, input().split())

d = deque()
current = "P"

for _ in range(1, N+1):
  d.appendleft("B")
  d.extend(current)
  d.append("P")
  d.extend(current)
  d.append("B")
  current = d

print(l.count("P"))

Submission status: Runtime Error

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

Submission status: Runtime Error

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


def func(level, x):
    if burger[level-1] + 1 <= x:
        return func(level-1, x-burger[level-1]-2) + patty[level-1] + 1
    else:
        return func(level-1, x-1)
    if level == 0:
        return 0


print(func(N, X))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
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
inf = float("INF")

#solve
def solve():
    n, x = LI()
    N, X = LI()

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


#main
if __name__ == '__main__':
    solve()

Submission status: Runtime Error

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

for i in range(1,n+1):
    ans = "B" + ans + "P" + ans + "B"

print(ans[:x].count("P"))

Submission status: Runtime Error

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()

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

print(rec(N,X))

Submission status: Runtime Error

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

"""
　　レベルnの層数：a_0 = 1 , a_n = 2*a_(n-1)+3
レベルnのパティ数：b_0 = 1 , b_n = 2*b_(n-1)+1
"""

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

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

def ans(n,x):
    if n == 0:
        return 1
    else:
        if x == 1:
            return 0
        if 1 < x <= thickness(n-1)+1:
            return ans(n-1,x-1)
        if x == thickness(n-1) + 2:
            return patty(n-1) + 1
        if thickness(n-1) + 2 < x <= 2 * thickness(n) + 2:
            return patty(n-1) + 1 + ans(n-1,x-2-thickness(n-1))
        if x == 2 * thickness(n-1) + 3:
            return 2 * patty(n-1) + 1

print(ans(N,X))

Submission status: Runtime Error

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

"""
　　レベルnの層数：a_0 = 1 , a_n = 2*a_(n-1)+3
レベルnのパティ数：b_0 = 1 , b_n = 2*b_(n-1)+1
"""

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

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

def ans(n,x):
    if n == 0:
        return 1
    else:
        if x == 1:
            return 0
        if 1 < x <= thickness(n-1)+1:
            return ans(n-1,x-1)
        if x == thickness(n-1) + 2:
            return patty(n-1) + 1
        if thickness(n-1) + 2 < x < 2 * thickness(n) + 2:
            return patty(n-1) + 1 + ans(n-1,x-2-thickness(n-1))
        if x == 2 * thickness(n-1) + 3:
            return 2 * patty(n-1) + 1

print(ans(N,X))

Submission status: Runtime Error

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

"""
　　レベルnの層数：a_0 = 1 , a_n = 2*a_(n-1)+3
レベルnのパティ数：b_0 = 1 , b_n = 2*b_(n-1)+1
"""

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

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

def ans(n,x):
    if x == 1:
        return 0
    if 1 < x <= thickness(n-1)+1:
        return ans(n-1,x-1)
    if x == thickness(n-1) + 2:
        return patty(n-1) + 1
    if thickness(n-1) + 2 < x < 2 * thickness(n) + 2:
        return patty(n-1) + 1 + ans(n-1,x-2-thickness(n-1))
    if x == 2 * thickness(n-1) + 3:
        return 2 * patty(n-1) + 1

print(ans(N,X))

Submission status: Runtime Error

Solution code:
import numpy as np
import sys
buf = sys.stdin.buffer

def main():
    N = int(buf.readline())
    A = np.frombuffer(buf.read(), dtype="int64")
    A = np.mod(A, 2)
    print("first") if np.count_nonzero(A) else print("second")
if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

"""
　　レベルnの層数：a_0 = 1 , a_n = 2*a_(n-1)+3
レベルnのパティ数：b_0 = 1 , b_n = 2*b_(n-1)+1
"""
def thickness(n):
    if n == 0:
        return 1
    else:
        return 2*thickness(n-1)+3

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

def ans(n,x):
    if x == 1:
        return 0
    if 1 < x <= thickness(n-1)+1:
        return ans(n-1,x-1)
    if x == thickness(n-1) + 2:
        return patty(n-1) + 1
    if thickness(n-1) + 2 < x < 2 * thickness(n) + 2:
        return patty(n-1) + 1 + ans(n-1,x-2-thickness(n-1))
    if x == thickness(n-1) + 3:
        return 2 * patty(n-1) + 1

print(ans(N,X))

Submission status: Runtime Error

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

a = [1]  # 厚さ
p = [1]  # パティの数
for i in range(N):
    a.append(2*a[-1] + 3)
    p.append(2*p[-1] + 1)


def f(n: int, x: int) -> int:
    """レベルnバーガーの下からx枚のパティの数
    """
    if x == 1:
        return 0 if n > 0 else 1
    elif x <= 1+a[n-1]:
        return f(n-1, x-1)
    elif x == 2 + a[n-1]:
        return p[n-1] + 1
    elif x <= 2*a[n-1] + 2:
        return p[n-1] + 1 + f(n-1, x - (2+a[n-1]))
    elif x == 2*a[n-1] + 3:
        return p[n]
    else:
        raise ValueError(f"xがレベルnバーガーの厚さより大きい, x={x}, n={n}")


if __name__ == "__main__":
    ans = f(N, X)
    print(ans)

Submission status: Runtime Error

Solution code:
import sys
N, X = map(int, input().split())
sys.setrecursionlimit(1_000_000_000)


def dfs(level, idx, cnt_p):
    if X == idx+1:
        return 0
    elif X < 2**(level+1)-3+2:
        return cnt_p + dfs(level-1, idx+1, cnt_p)
    elif X == 2**(level+1)-3+2:
        return 2**(level)-1 + 1
    else:
        return cnt_p + 2**(level)-1 + 1 + dfs(level-1, idx+2**(level+1)-2, cnt_p)


ans = dfs(N, 0, 0)
print(ans)

Submission status: Runtime Error

Solution code:
from functools import lru_cache
import sys
N, X = map(int, input().split())
sys.setrecursionlimit(1_000_000_000)


@lru_cache(maxsize=1000)
def dfs(level, idx, cnt_p):
    if X == idx+1:
        return 0
    elif X < 2**(level+1)-3+2:
        return cnt_p + dfs(level-1, idx+1, cnt_p)
    elif X == 2**(level+1)-3+2:
        return 2**(level)-1 + 1
    else:
        return cnt_p + 2**(level)-1 + 1 + dfs(level-1, idx+2**(level+1)-2, cnt_p)


ans = dfs(N, 0, 0)
print(ans)

Submission status: Runtime Error

Solution code:
def burger_size(N):
    if N == 0:
        return 1
    return 3 + 2 * burger_size(N - 1)

def burger_patty_num(N):
    if N == 0:
        return 1
    return 1+ 2 * burger_patty_num(N - 1)

def patty_num(N, X):
    if X == 0:
        return 0
    if X <= 1 + burger_size(N - 1):
        return patty_num(N - 1, X - 1)
    elif X == 2 + burger_size(N - 1):
        return 1 + burger_patty_num(N - 1)
    elif X <= 2 + 2 * burger_size(N - 1):
        return 1 + burger_patty_num(N - 1) + patty_num(N - 1, X - (2 + burger_size(N - 1)))
    else:
        return 1 + 2 * burger_patty_num(N - 1)
        
    
N, X = map(int, input().split())
print(patty_num(N, X))

Submission status: Runtime Error

Solution code:
def burger_size(N):
    if N == 0:
        return 1
    return 3 + 2 * burger_size(N - 1)

def burger_patty_num(N):
    if N == 0:
        return 1
    return 1+ 2 * burger_patty_num(N - 1)

def patty_num(N, X):
    if X == 0:
        return 0
    if X <= 1 + burger_size(N - 1):
        return patty_num(N - 1, X - 1)
    elif X == 2 + burger_size(N - 1):
        return 1 + burger_patty_num(N - 1)
    elif X > 2 + burger_size(N - 1):
        return 1 + burger_patty_num(N - 1) + patty_num(N - 1, X - (2 + burger_size(N - 1)))
        
    
N, X = map(int, input().split())
print(patty_num(N, X))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
n, x = map(int,input().split())

def solv(n):
    if n == 0:
        return 'P'
    else:
        tmp = solv(n - 1)
        return 'B' + tmp + 'P' + tmp + 'B'

ans = solv(n)
print(list(ans[:x]).count('P'))

Submission status: Runtime Error

Solution code:
n,x = map(int, input().split())
memo = [0]*(n+1)
memo[0]="P"
def b(m):
    if (memo[m] != 0):
        return memo[m]    
    else:
        memo[m]= "B" + b(m-1) + "P" + b(m-1) + "B"
        return memo[m]
print(b(n)[:x].count("P"))

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10000)

N, X = map(int, input().split())
Burger = ['P']
for i in range(1,N+1):
    Burger_ = 'B' + Burger[i-1] + 'P' + Burger[i-1] + 'B'
    Burger.append(Burger_)
print(Burger[N][0:X].count('P'))

Submission status: Runtime Error

Solution code:
N, X = map(int, input().split())
Burger = ['P']
for i in range(1,N+1):
    Burger_ = 'B' + Burger[i-1] + 'P' + Burger[i-1] + 'B'
    Burger.append(Burger_)
print(Burger[N][0:X].count('P'))

Submission status: Runtime Error

Solution code:
n, x = map(int, input().split())
a = "BPPPB"
a = "B"+a+"P"+a+"B"

for _ in range(n-1):
    a = "B" + a + "P" + a + "B"

list_A = list(a)
b = list_A[:x+1]
print(b.count("P"))

Submission status: Runtime Error

Solution code:
n,x = map(int, input().split())
ba = "p"
for i in range(n):
    ba = "b" + ba + "p" + ba +"b"
print(ba[:x].count("p"))

Submission status: Runtime Error

Solution code:

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

def make_burger(n):
    if n == 0:
        return "P"
    else:
        L = make_burger(n - 1)
        return "B" + L + "P" + L + "B"
    

b = make_burger(n)
ans = 0
for i in range(len(b) - 1, len(b) - x - 1, -1):
    if b[i] == "P":
        ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
def solve(n, x):
    layers = 2 ** (n + 1) - 3  # レベルn-1バーガーの層の数
    patties = 2 ** n - 1    # レベルn-1バーガーのパティの数
    if x == 0:
        ans = 0
    elif x <= layers + 1:
        ans = solve(n - 1, x - 1)
    else:
        ans = patties + 1 + solve(n - 1, x - layers - 2)
        
    return ans

N, X = [int(x) for x in input().split()]
print(solve(N, X))

Submission status: Runtime Error

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

def burger(N,X):
  #print(N,X)
  if N == 0 and X == 1:
    return 1
  if X == 0:
    return 0
  twopow = pow(2,N)
  if X > 2*twopow-2:
    return twopow + burger(N-1,X-2*twopow+1)
  elif X <= 2*twopow-2:
    return burger(N-1,X-1)

print(burger(N,X))

Submission status: Runtime Error

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

def burger(N,X):
  #print(N,X)
  if N == 0 and X == 1:
    return 1
  if X == 0:
    return 0
  twopow = pow(2,N)
  if X > 2*twopow-2:
    return twopow + burger(N-1,X-2*twopow+1)
  elif X <= 2*twopow-3:
    return burger(N-1,X-1)

print(burger(N,X))

Submission status: Runtime Error

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

def burger(N,X):
  print(N,X)
  if N == 0 and X == 1:
    return 1
  if X == 0:
    return 0
  twopow = pow(2,N)
  if X > 2*twopow-2:
    return twopow + burger(N-1,X-2*twopow+1)
  elif X <= 2*twopow-3:
    return burger(N-1,X-1)

print(burger(N,X))

Submission status: Runtime Error

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


def p(level):
    if level == 0:
        return 1
    return 2*p(level-1)+1


def a(level):
    if level == 0:
        return 1
    return 2*a(level-1)+3


def f(level, x):
    if x <= 1:
        return 0
    else:
        ai_1 = a(level-1)
        if 1 < x <= 1 + ai_1:
            return f(level-1, x-1)
        else:
            pi_1 = p(level-1)
            return 1 + pi_1+f(level-1, x-2-ai_1)


print(f(n, x))

Submission status: Runtime Error

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


def p(level):
    if level == 0:
        return 1
    return 2*p(level-1)+1


def a(level):
    if level == 0:
        return 1
    return 2*a(level-1)+3


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


print(f(n, x))

Submission status: Runtime Error

Solution code:
n,x=map(int,input().split())
s="P"
for _ in range(n):
    s='B'+s+'P'+s+'B'
print(s[-1*x:].count('P'))

Submission status: Runtime Error

Solution code:
import sys
from functools import lru_cache
input=sys.stdin.readline

@lru_cache(maxsize=None)
def hungry(A):
    if A<1:
        return "P"
    return "B"+hungry(A-1)+"P"+hungry(A-1)+"B"

n,k=map(int,input().split())
print(hungry(n)[-k:].count("P"))

Submission status: Runtime Error

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

patty = [2**(i+1)-1 for i in range(n+1)][::-1]
length = [2**(i+2)-3 for i in range(n+1)][::-1]

ans=0
end=[0,1,2,3,3]

for i in range(n):
    hambergar=[1,1+length[i+1],2+length[i+1],2+2*length[i+1],3+2*length[i+1]]
    if i==n-1:
        ans+=end[x-1]
    else:
        if hambergar[0]<x and x<hambergar[2]:
            x-=1
        
        elif hambergar[2]<x and x<=hambergar[4]:
            ans+=patty[i+1]+1
            x-=hambergar[2]
        
        elif hambergar[2]==x:
            ans+=patty[i+1]+1
            break
        
        elif hambergar[4]<x or x<=1:
            break

print(ans)

Submission status: Runtime Error

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

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: Runtime Error

Solution code:
a,b = map(int,input().split())
for i in range(a):
  a = "B"+a+"P"+a+"B"
print(a[:b])

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def count(n,x):
    if x<=n:
        return 0
    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))

Submission status: Runtime Error

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),
                   buns[dimension - 1] + patty[dimension - 1], dimension - 1) + patty[dimension - 1] + 1


print(dfs(X, burger_high, N))