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: Time Limit Exceeded

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

position = 2**(n+2)-3
result = 0
while x > 0:
    position = (position-1)//2
    if x > position:
        x -= position
        result += position//2+1
    x -= 1
    position -= 1
print(result)

Submission status: Time Limit Exceeded

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

position = 2**(n+2)-3
result = 0
while x > 0:
    n -= 1
    if x <= (position-1)//2:
        x -= 1
    else:
        x -= (position-1)//2 + 1 
        result += (position+3)//4
    position = (position-3)//2
print(result)

Submission status: Time Limit Exceeded

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

position = 2**(n+2)-3
result = 0
while x > 0:
    n -= 1
    if x <= (position-1)//2:
        x -= 1
    else:
        x -= (position-1)//2 + 1 
        result += 2**(n+1)
    position = 2**(n+2)-3
print(result)

Submission status: Time Limit Exceeded

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

@lru_cache(maxsize=1000)
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: Time Limit Exceeded

Solution code:
import sys
input=sys.stdin.readline
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: Time Limit Exceeded

Solution code:
def burger(L):
    if L == 0:
        return 'P'
    else:
        return 'B' + burger(L-1) + 'P' + burger(L-1) + 'B'
    
N, K = map(int, input().split())
print(burger(N)[-K:].count('P'))

Submission status: Time Limit Exceeded

Solution code:
N,X = map(int, input().split())
def humbarger(N):
    if N==0:
        return 'P'
    return 'B'+ humbarger(N-1)+'P'+ humbarger(N-1) + 'B'
print(humbarger(N)[:X].count('P'))

Submission status: Time Limit Exceeded

Solution code:
N,X = map(int, input().split())
def humbarger(N):
    if N==0:
        return 'P'
    hum1 = 'B%s'% humbarger(N-1)
    hum2 = '%sB'% humbarger(N-1)
    return hum1+'P'+ hum2
servey = humbarger(N)[:X]
print(servey.count('P'))

Submission status: Time Limit Exceeded

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


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

count = 0
l = list(burger(n))

for c in range(0, len(l) - 1):
  if l[c] == "P":
       count += 1
   
  if c == x-1:
       break

print(count)

Submission status: Time Limit Exceeded

Solution code:
def createBurger(n):
    if n == 0:
        return 'P'
    if n > 0:
        return ''.join(['B', createBurger(n-1),'P',createBurger(n-1),'B'])

n,x = map(int, input().split())
ans = 0
burger = createBurger(n)
for i in range(x):
    if burger[i] == 'P':
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

lv1='BPPPB'
temp='BPPPB'
cnt=1
while cnt<n:
    temp='B'+lv1+'P'+lv1+'B'
    cnt+=1
    lv1=temp

count=0
for i in temp:
    x-=1
    if i=='P':
        count+=1

    if x==0:
        print(count)

Submission status: Time Limit Exceeded

Solution code:
def berger(N):
    if N <= 0 :
        return "P"
    DP[N] = "B" + berger(N-1) + "P" + berger(N-1) + "B"
    return DP[N]

N, X = map(int, input().split())
DP = [""] * (N+1)
DP[0] = "P"
berger(N)
print(DP[N][len(DP[N])-X:].count('P'))

Submission status: Time Limit Exceeded

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

dp = [[0 for _ in range(X)] for _ in range(N)]
layers_num = [0 for _ in range(N)]

layers_num[0] = len(level0)

for x in range(X):
    if x < len(level0):
        pb = level0[x]
        if x == 0:
            if pb == 'P':
                dp[0][x] = 1
        else:
            if pb == 'P':
                dp[0][x] = dp[0][x-1] + 1
            else:
                dp[0][x] = dp[0][x-1]
    else:
        dp[0][x] = dp[0][x - 1]

for n in range(1, N):
    layers_num[n] = 2 * layers_num[n-1] + 3

    for x in range(X):
        if x == 0:
            dp[n][x] = 0
        elif 0 < x and x <= layers_num[n - 1]:
            dp[n][x] = dp[n - 1][x - 1]
        elif x == layers_num[n-1] + 1:
            dp[n][x] = dp[n - 1][x - 1] + 1
        else:
            dp[n][x] = dp[n - 1][x - 1] + 1 + dp[n - 1][x - layers_num[n-1] - 2]

print(dp[-1][-1])

Submission status: Time Limit Exceeded

Solution code:
n,x = map(int,input().split())
b = "P"
for _ in range(n):
    b = "B"+b+"P"+b+"B"

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

Submission status: Time Limit Exceeded

Solution code:
def burger(n):
    if n == 0:
        return "P"
    else:
        return "B"+burger(n-1)+"P"+burger(n-1)+"B"

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

ans = 0
nburger = list(burger(N))
for i in range(X):
    if nburger[i] == "P":
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

for i in range(0, N):
    L = "B" + L + "P" + L + "B"
print(L[:X].count('P'))

Submission status: Time Limit Exceeded

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

from functools import lru_cache
import sys

sys.setrecursionlimit(10*20)

def count(N):
    if N == 0:
        return 1
    else:
        return 3 + 2 * count(N-1)
    
def calc(N,X):
    if N == 0:
        return 1
    center = count(N-1) + 1
    if X == 0 :
        return 0
    elif X < center:
        return calc(N-1,X-1)
    elif X == center:
        return calc(N-1,center-2) + 1
    elif X > center:
        return calc(N-1,X-center-1) + calc(N,center)
print(calc(N,X-1))

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
from itertools import groupby

n,x = [int(x) for x in stdin.readline().rstrip().split()]

s = "P"

def morimori(s):
    m = "B" + s + "P" + s[::-1] + "B"
    return m

for i in range(n):
    s = morimori(s)

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

Submission status: Time Limit Exceeded

Solution code:

def Burger(n, b):
  if n == 0:
    return "P"
  b += "B"
  b += Burger(n-1, "")
  b += "P"
  b += Burger(n-1, "")
  b += "B"
  return b

n, x = [int(x) for x in input().split()]
burger = Burger(n, "")
print(burger[-x:].count("P"))

Submission status: Time Limit Exceeded

Solution code:
nx = input()
nx = nx.split()
n = int(nx[0])
x = int(nx[1])
burgers = [None] * 51
burgers[0] = "P"
burgers[1] = "BPPPB"
burgers[2] = "BBPPPBPBPPPBB"
i = 3
while i<=50:
  burgers[i] = "B" + burgers[i-1] + "P" + burgers[i-1] + "B"
  i+=1
result = burgers[n][:x-1]
print(result.count("P"))

Submission status: Time Limit Exceeded

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

def hamburger(L):
	if L == 0:
		return "P"
	else:
		return "B" + hamburger(L - 1) + "P" + hamburger(L - 1) + "B"
		
		
print(list(hamburger(N))[0 : X].count("P"))

Submission status: Time Limit Exceeded

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

for i in range(n):
    bg = "B" + bg + "P" + bg + "B"

bg_x = bg[-x:]
print(bg_x.count("P"))

Submission status: Time Limit Exceeded

Solution code:
dp = ["" for i in range(51)]
dp[0] = "P"

def solve(n, dp):
    if n == 0:
        return dp[0]
    else:
        if dp[n] == "":
            return 'B' + solve(n - 1,dp) + 'P' + solve(n - 1,dp) + 'B'
        else:
            return dp[n]
n, x = list(map(int, input().split()))
dp = solve(n,dp)
print(dp[-x:].count('P'))

Submission status: Time Limit Exceeded

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

def barger(n):
    if n == 0 :
        return "1"
    else:
        return "0" + barger(n-1) + "1" + barger(n-1) + "0"

print(barger(n)[:x].count("1"))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

def burger(n):
  if n == 0:
    return '1'
  else:
    return '0' + burger(n-1) + '1' + burger(n-1) + '0'

N,X = map(int,input().split())
print(Counter(burger(N)[:X])['1'])

Submission status: Time Limit Exceeded

Solution code:
def solve():
    N,X = map(int, input().split())
    def burger(n):
        if n == 0:
            return 'P'
        else:
            return 'B' + burger(n-1) + 'P' + burger(n-1) + 'B'
    return burger(N)[:X].count('P')

if __name__ == '__main__':
    print(solve())

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:

# レベルNバーガー生成 B=0 P=1
def berger(n):
    if n == 0:
        return [1]
    else:
        B = berger(n-1)
        A = [0]
        A.extend(B)
        A.append(1)
        A.extend(B)
        A.append(0)
        return A

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

C = berger(n)
count = 0
for i in range(x):
    count += C[i]

print(count)

Submission status: Time Limit Exceeded

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

def burger(s, n):
    if n == 0:
        return str(s)
    s = 'B'+burger(s, n-1)+'P'+burger(s, n-1)+'B'
    return str(s)
    
print(burger('P', N)[0:X].count('P'))

Submission status: Time Limit Exceeded

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

def dp(n):
    if n == 0:
        return ["P"]
    k = dp(n-1)
    return ["B"]+k+["P"]+k+["B"]

burger = dp(n)
burger = "".join(burger)
ans = burger[:x].count("P")
print(ans)

Submission status: Time Limit Exceeded

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):
#  print (n, a[n], x)
  if n == 0:
    return 0
  elif n == 1:
    return "BPPPB"[:x].count("P")
  else: 
    if x <= 0:
      return 0
    elif x <= 1 + a[n-1]:
      return f(n-1, x-1)  
    else:
      return f(n-1,a[n-1])+f(n-1,x - 2 - a[n-1]) +1
print (f(N, X))

Submission status: Time Limit Exceeded

Solution code:
N, X = map(int, input().split())
dp = [''] * (N + 1)
dp[0] = 'P'

for i in range(1, N + 1):
	dp[i] = 'B' + dp[i - 1] + 'P' + dp[i - 1] + 'B'
	
print(dp[N][0:X].count('P'))

Submission status: Time Limit Exceeded

Solution code:
def burger(l):
    if not l:
        return 'P'
    s = 'B' + burger(l - 1) + 'P' + burger(l - 1) + 'B'
    return s
s = ''
n, x = map(int, input().split())
print(burger(n)[:x].count('P'))

Submission status: Time Limit Exceeded

Solution code:
zb = [1]
 
def burger(lst):
  bls = [0]
  bls.extend(lst)
  bls.append(1)
  bls.extend(lst)
  bls.append(0)
  
  return bls
 
n, x = map(int, input().split())

for i in range(n):
  zb = burger(zb)

print(sum(zb[:x]))

Submission status: Time Limit Exceeded

Solution code:
# n次元バーガーの[全段数,パティ枚数]
def burger(n):
    if n == 0:
        return [1,1]
    return [burger(n-1)[0]*2+3,burger(n-1)[1]*2+1]

# レベルn, 下からx段, 食べるパティp枚
def eat(n,x):
    if n==0:
        if x>0:
            return 1
        else:
            return 0
    if x < 1:
        return 0
    if 1 <= x <= 1+burger(n-1)[0]:
        return eat(n-1,x-1)
    if x == 2 + burger(n-1)[0]:
        return burger(n-1)[1]+1
    if x>2+burger(n-1)[0]:
        return eat(n-1,x-2-burger(n-1)[0])+burger(n-1)[1]+1

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

print(eat(n,x))

Submission status: Time Limit Exceeded

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

# 0:b, 1:p
b = [0,1,1,1,0]

for _ in range(n-1):
    b = [0] + b + [1] + b + [0]

print(sum(b[:x]))

Submission status: Time Limit Exceeded

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

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

burger = makeBurger(N + 1)
#print(burger)
result = burger[len(burger)-X:]
print(result.count('P'))

Submission status: Time Limit Exceeded

Solution code:
n, x = map(int, input().split())
import numpy as np


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


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

    i, p, eaten = 0, 0, 0

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

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

    print(p)


main(n, x)

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
l=["p"]
i=0
while len(l)<m:
  i+=1
  l=["b"]+l+["p"]+l+["b"]
for j in range(n-i):
  l=["b"]+l
c=0
for i in range(m):
  if l[i]=="p":
    c+=1
print(c)

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
l=["p"]
i=0
while len(l)<m:
  i+=1
  l=["b"]+l+["p"]+l+["b"]
for j in range(n-i):
  l=["b"]+l
c=0
for i in range(m):
  if l[i]=="p":
    c+=1
print(c)

Submission status: Time Limit Exceeded

Solution code:
def f(N, X):
    if N == 0:
        return 1

    if X == 1:
        return 0
    before = get_N(N - 1)
    if X >= 2 and X <= 1 + before:
        return f(N - 1, X - 1)
    if X == 2 + before:
        return f(N - 1, before) + 1
    #X >= 3 + before
    return f(N - 1, before) + 1 + f(N - 1, X - before - 2)

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

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

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(100000)
def l_burger(l):
    if l == 0:
        return 'P'
    return 'B' + l_burger(l-1) + 'P' + l_burger(l-1) + 'B'
n, x = map(int, input().split())
cnt = 0
for i in l_burger(n)[:x]:
    if i == 'P':
        cnt += 1
        
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N, X = map(int, input().split())
def barger(n):
    if n == 0:
        return [1]
    else:
        return [0]+barger(n-1)+[1]+barger(n-1)+[0]

levN = barger(N)
print( sum(levN[0:X]))

Submission status: Time Limit Exceeded

Solution code:
N,X = map(int,input().split())
def f(N):
    if(N == 0):
        return 'P'
    else:
        return 'B' + f(N-1) + 'P' + f(N-1) + 'B'
burger = f(N)
burger = burger[0:X]
print(burger.count('P'))

Submission status: Time Limit Exceeded

Solution code:
def putty(n):
    f_last = [1]
    tmp = [1]
    for i in range(1, n+1):
        tmp = [0]+f_last+[1]+f_last+[0]
        f_last = tmp
    return tmp

n, x = map(int, input().split())
#f = [[]] * (n+1)
a = putty(n)
a = a[:x]
print(sum(a))

Submission status: Time Limit Exceeded

Solution code:
def putty(n):
    if (n == 0):
        return [1]
    return [0]+putty(n-1)+[1]+putty(n-1)+[0]

n, x = map(int, input().split())
a = putty(n)
a = a[:x]
print(sum(a))

Submission status: Time Limit Exceeded

Solution code:
def putty(n):
    if (n == 0):
        return "P"
    return "B"+putty(n-1)+"P"+putty(n-1)+"B"

n, x = map(int, input().split())
a = putty(n)
a = a[:x]
print(a.count("P"))

Submission status: Time Limit Exceeded

Solution code:
N,X=map(int,input().split())
l=[2**(i+2)-3 for i in range(N+1)]#レベルLバーガー層数
p=[2**(i+1)-1 for i in range(N+1)]#レベルL パティ数
bp=[[0 for i in range(X+1)] for j in range(N+1)]
bp[0][1]=1
for i in range(N):
    for j in range(X+1):
        if j==1:
            bp[i+1][j]=0
        elif 1<j<=l[i]+1:
            bp[i+1][j]=bp[i][j-1]
        elif j==l[i]+2:
            bp[i+1][j]=p[i]+1
        elif l[i]+2<j<l[i+1]:
            bp[i+1][j]=p[i]+1+bp[i][j-l[i]-2]
        elif j==l[i+1]:
            bp[i+1][j]=p[i+1]
print(bp[N][X])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def f(n):
  if n==0:
    return 'P'
  else:
    return 'B'+f(n-1)+'P'+f(n-1)+'B'

N,X=(int(i) for i in input().split())
L=list(f(N)[-1:-X-1:-1])
print(L.count('P'))

Submission status: Time Limit Exceeded

Solution code:
N,X=map(int,input().split())
def f(n):
    if n==0:
        return [1]
    else:
        return [0]+f(n-1)+[1]+f(n-1)+[0]
print(sum(f(N)[i] for i in range(X)))

Submission status: Time Limit Exceeded

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

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

eat = burger(N)[ : X]
print(eat.count('P'))

Submission status: Time Limit Exceeded

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

def solve(N,K):
    #B=1,P=0
    burger = 0
    l = 1
    for i in range(N):
        burger = 1 + burger*10 + burger*(10**(l+2)) + 10**(l*2+2)
        l = 2*l+3
        #print(burger)
    ans = K - str(burger//10**(l-K)).count('1')
    print(ans)
    return

solve(N,K)

Submission status: Time Limit Exceeded

Solution code:
def make_burger(N):
  if N == 0:
    return "P"
  else:
    burger_half = "B" + make_burger(N - 1)
    return burger_half + "P" + burger_half[::-1]

N, X = map(int, input().split())
burger = make_burger(N)
ans = 0
for i in range(X):
  if burger[i] == "P":
    ans += 1
print(ans)

Submission status: Time Limit Exceeded

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


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


print(hamburg(N)[:X].count("P"))

Submission status: Time Limit Exceeded

Solution code:
n,x = map(int, input().split())
def burger(x):
    if x==0:
        return 'P'
    else:
        return 'B'+burger(x-1)+'P'+burger(x-1)+'B'
burger = burger(n)
print(burger[:x].count('P'))

Submission status: Time Limit Exceeded

Solution code:
N,X=map(int,input().split())
def humberger(N):
    if N==0:
        return [1]
    else:
        return [0]+humberger(N-1)+[1]+humberger(N-1)+[0]
list1=humberger(N)
del list1[X:]
print(sum(list1))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

import sys
sys.setrecursionlimit(1000000000)

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


def countPatty(N, X):

    if X == 0:
        return 0, 0

    if N == 0:
        return 1, X - 1

    # First inner burger
    nPatty, restX = countPatty(N - 1, X - 1)

    if restX == 1:
        nPatty, restX = nPatty + 1, 0
    elif restX >= 2:
        tPatty, restX = countPatty(N - 1, restX - 1)
        nPatty, restX = nPatty + tPatty + 1, restX - 1

    return nPatty, restX


nPatty, restX = countPatty(N, X)
print(nPatty)

Submission status: Time Limit Exceeded

Solution code:
n,x = map(int,input().split())
n_burgar = ["P"]
m=0
for i in range(0,n):
    m_burgar=[]
    for item in n_burgar:
        m_burgar.append(item)
    n_burgar.insert(m,"B")
#    for item in m_burgar:
#        m=m+1
#        n_burgar.insert(m,item)
    n_burgar.insert(m+1,"P")
    for item in m_burgar:
        m=m+1
        n_burgar.insert(m,item)
    n_burgar.insert(m+3,"B")
    m=0
n_burgar.reverse()
m
for i in range(0,x):
    if n_burgar[i] == "P":
        m=m+1
print(m)

Submission status: Time Limit Exceeded

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

def lv(n):
    if n == 0:
        yield 'P'
    else:
        yield 'B'
        for q in lv(n-1):
            yield q
        yield 'P'
        for q in lv(n-1):
            yield q
        yield 'B'

k = 0
i = 0
for n in lv(N):
    #print(n)
    if n == 'P':
        i += 1
    
    k += 1
    
    if k >= X:
        break

print(i)

Submission status: Time Limit Exceeded

Solution code:
n,x=map(int,input().split())
B=[1]
for i in range(n):
    B=[0]+B+[1]+B+[0]
print(sum(B[:x]))

Submission status: Time Limit Exceeded

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

def f(n):
	if n < 1:
		return 'P'
	return 'B' + f(n-1) + 'P' + f(n-1) + 'B'

count = 0
for i in f(N)[0:X]:
	if i == 'P':
		count += 1
		
print(count)

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())
def dfs(level,req,seq):
  if len(seq)==req:
    return
  if level==0:
    seq.append("P")
    return
  elif level>=1:
    seq.append("B")
    level-=1
    dfs(level,req,seq)
    seq.append("P")
    dfs(level,req,seq)
    seq.append("B")
    return seq
seq=[] 
if N==K==1:
  print("0")
else:
  seq=dfs(N,K,seq)
  #ans=seq[:K]
  ans=[i for i in seq if i=='P']
  print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
def level(x):
    L.append('B')
    if x>1:
        level(x-1)
    else:
        L.append(L0)
    L.append('P')
    if x>1:
        level(x-1)
    else:
        L.append(L0)
    L.append('B')


N,X = map(int,input().split())
count=0
L0 = 'P'
L = []
level(N)
for i in range(X):
    if L[i]=='P':
        count+=1

print(count)

Submission status: Time Limit Exceeded

Solution code:
N, X = map(int, input(). split())
ban = [0]
patty = [1]

B = [1]
for i in range(N):
    B = ban + B + patty + B + ban

print(sum(B[:X]))

Submission status: Time Limit Exceeded

Solution code:
l = input().split()
n = int(l[0])
x = int(l[1])
bn_1 = 'p'
for i in range(n):
  bn = 'b' + bn_1 + 'p' + bn_1 + 'b'
  bn_1 = bn
print(bn[:x].count('p'))

Submission status: Time Limit Exceeded

Solution code:
import copy
 
# TODO TLE
n, k = map(int, input().split())
 
result = "P"
if n > 0:
    for _ in range(n):
        result = "B" + result + "P" + result + "B"
print(result[-k:].count("P"))

Submission status: Time Limit Exceeded

Solution code:
import copy

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

result = ["P"]
if n > 0:
    for _ in range(n):
        temp_l = copy.deepcopy(result)
        result = ["B"]
        result.extend(temp_l)
        result.extend(["P"])
        result.extend(temp_l)
        result.extend(["B"])
print(result[-k:-1].count("P"))

Submission status: Time Limit Exceeded

Solution code:
def b(n): # n次元バーガー
    if n == 0:
        return "P "
    else:
        return "B " + b(n-1) + "P " + b(n-1) + "B "
n, x= map(int, input().split())
print(b(n).split(" ", x).count("P"))

Submission status: Time Limit Exceeded

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

for n in range(N+1):
    if n == 0:
        burger = 'P'
    else:
        burger = 'B' + burger + 'P' + burger + 'B'

print(list(burger)[-X:-1].count('P'))

Submission status: Time Limit Exceeded

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


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


print(burger(n)[:x].count('P'))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n,x=(int(i) for i in input().split())

def makeBurger(s):
    return "B"+s+"P"+s+"B"
s = "P"
if(n>0):
    for i in range(n):
        s = makeBurger(s)
count = 0
for i in range(x):
    if s[i]=='P':
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
def make_N_B(N):
    if N == 1:
        return str('BPPPB')
    return str('B') + make_N_B(N-1) + str('P') + make_N_B(N-1) + str('B')

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

B_split_count = list(make_N_B(N))[:X].count('P')
print(B_split_count)

Submission status: Time Limit Exceeded

Solution code:
def burger(L):
    if L > 0:
        st = 'B' + burger(L-1) + 'P' + burger(L-1) + 'B'
        return st
    else:
        return 'P'

N, X = map(int, input().split())
st = burger(N)
a = 0
for i in range(X):
    if st[i] == 'P':
        a += 1
print(a)

Submission status: Time Limit Exceeded

Solution code:
a = input().split()
n = int(a[0])
x = int(a[1])

b = 'P'
for i in range(n):
    c = b
    b = 'B'+c+'P'+c+'B'

e = []
for i in range(x):
    e.append(b[-i-1])

count = 0
for i in e:
    if i  == 'P':
        count = count + 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
a = input().split()
n = int(a[0])
x = int(a[1])
n0 = 'P'

b = 'P'
for i in range(n):
    c = b
    b = 'B'+c+'P'+c+'B'

e = []
for i in range(x):
    e.append(b[-i-1])

count = 0
for i in e:
    if i  == 'P':
        count = count + 1
print(count)

Submission status: Time Limit Exceeded

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

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

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

# gen burger
print(gen_burger(n)[:x].count('P'))

Submission status: Time Limit Exceeded

Solution code:
N, X = map(int,input().split())
p = 1
b = 0
burger = [p]
for i in range(N):
    burger=[b,burger,p,burger,b]
    
def flatten(nested_list):
    # フラットなリストとフリンジを用意
    flat_list = []
    fringe = [nested_list]

    while len(fringe) > 0:
        node = fringe.pop(0)
        # ノードがリストであれば子要素をフリンジに追加
        # リストでなければそのままフラットリストに追加
        if isinstance(node, list):
            fringe = node + fringe
        else:
            flat_list.append(node)
    return flat_list

burger_f = flatten(burger)
eat = 0
for j in range(X):
     eat +=burger_f[j]

print(eat)

Submission status: Time Limit Exceeded

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

# gen burger
burger = 'P'
for i in range(0, n):
    burger = 'B' + burger + 'P' + burger + 'B'

# eat
burger = burger[len(burger)-x:]
print(burger.count('P'))

Submission status: Time Limit Exceeded

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

# gen burger
burger = ''
for i in range(0,n):
    if i == 0:
        burger = 'P'
    burger = 'B' + burger + 'P' + burger + 'B'

# eat
burger = burger[len(burger)-x:]
print(burger.count('P'))

Submission status: Time Limit Exceeded

Solution code:
#! /usr/bin/env python3
# -*- coding: utf-8 -*-


from itertools import chain


nnx = list(map(lambda x: int(x) ,input().split(" ")))
n = nnx[0]
x = nnx[1]

ndburger = ["1"]
for l in range(n):
    ndburger = list(chain.from_iterable(["0",ndburger,"1",ndburger,"0"]))

ndburger_x = [l for l in ndburger[:x] if l == "1"]
print(len(ndburger_x))

Submission status: Time Limit Exceeded

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

for i in range(1, 55):
    b_len += [ b_len[i-1] * 2 + 3 ]

t = [0, 1, 2, 3, 3]

def solve(N, X):
    if N == 0:
        return 1
    elif N == 1:
        if X > 5:
            return t[4]
        else:
            return t[X-1]
    elif X <= b_len[N-1] + 1:
        return solve(N-1, X-1)
    elif X == b_len[N-1] + 2:
        return solve(N-1, b_len[N-1]) + 1
    else:
        return solve(N-1, b_len[N-1]) + 1 + solve(N-1, X-b_len[N-1]-2)

print (solve(N, X))

Submission status: Time Limit Exceeded

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

for i in range(1, 55):
    b_len += [ b_len[i-1] * 2 + 3 ]

def solve(N, X):
    if N == 0:
        return 1
    elif N == 1:
        return ("BPPPB"[-X:]).count("P")
    elif X <= b_len[N-1] + 1:
        return solve(N-1, X-1)
    elif X == b_len[N-1] + 2:
        return solve(N-1, b_len[N-1]) + 1
    else:
        return solve(N-1, b_len[N-1]) + 1 + solve(N-1, X-b_len[N-1]-2)

print (solve(N, X))

Submission status: Time Limit Exceeded

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


def make_burger(l):
    burger = 'P'
    for i in range(l):
        burger = 'B' + burger + 'P' + burger + 'B'
    return burger


print(make_burger(n)[:x].count('P'))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
 
def burg(l):
    if l ==0:
        return "P"
    else:
        return "B"+burg(l-1)+"P"+burg(l-1)+"B"

n, x = map(int, input().split())
eaten = burg(n)[0:x]
print(eaten.count("P"))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

"""
ひとつ前だけ取っておく
"""

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

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

print(cur[:X].count('P'))

Submission status: Time Limit Exceeded

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

for i in range(N):
    L = "B" + prevL + "P" + prevL + "B"
    prevL = L
run_eats = L[::-1][0:X]
print(run_eats.count("P"))

Submission status: Time Limit Exceeded

Solution code:
N, X = list(map(int, input().split()))
bg = ["P"]
ans = 0

for i in range(N):
    bg = ["B"] + bg + ["P"] + bg + ["B"]
else:
    for i in range(X):
        if bg[i] == "P":
            ans += 1
    else:
        print(ans)

Submission status: Time Limit Exceeded

Solution code:
N , X = map(int,input().split())
def B(N):
    if N == 1:
        return ['B','P','P','P','B']
    B_lis = []
    B_lis.append('B')
    for i in B(N-1):
        B_lis.append(i)
    B_lis.append('P')
    for i in B(N-1):
        B_lis.append(i)
    B_lis.append('B')
    return B_lis
l = B(N)
p = 0

for i in range(X):
    if l[i] == 'P':
        p += 1
print(p)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
N,X = [int(i) for i in input().split()]

L = "P"
for i in range(N):
    LL = "B"+L+"P"+L+"B"
    L = LL
 
LLL = LL[-X:]
print(LLL.count("P"))

Submission status: Time Limit Exceeded

Solution code:
def dfs (i,depth):

    if i >= depth-1:
        return 'bpppb'
    else:
        return 'b' + dfs(i+1,depth) + 'p' + dfs(i+1,depth) + 'b'

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

r = dfs(0,n)
print(r.count('p',0,x))

Submission status: Time Limit Exceeded

Solution code:
N,X = list(map(int,input().strip().split()))
num = "1"

if N == 0:
    ans = "1"
else:
    for i in range(N):
        ans = "0"+num+"1"+num+"0"
        num = ans

alist = [i for i in str(ans)]
ans_list = list(map(int,alist))

print(sum(ans_list[-X:]))

Submission status: Time Limit Exceeded

Solution code:
def barger(m,s):
    if m==1:
        return 'B'+s+'P'+s+'B'
    else:
        return 'B'+barger(m-1,s)+'P'+barger(m-1,s)+'B'

n=input().split()
n=[int(i) for i in n]

if n[0]==0:
    s="P"
else:
    s=barger(n[0],"P")

r=list(s)

r=r[len(r)-n[1]:]
r=[i for i in r if i=="P"]
print(len(r))

Submission status: Time Limit Exceeded

Solution code:
def barger(m,s):
    if m==1:
        return 'B'+s+'P'+s+'B'
    else:
        return 'B'+barger(m-1,s)+'P'+barger(m-1,s)+'B'

n=input().split()
n=[int(i) for i in n]
#print(n)

if n[0]==0:
    s="P"
else:
    s=barger(n[0],"P")

r=list(s)
#print(r)
c=0
for i in range(0,n[1]):
    #print(r[i+len(s)-n[1]])
    if r[i+len(s)-n[1]]=="P":
        c+=1
print(c)

Submission status: Time Limit Exceeded

Solution code:
n, x = input().strip().split(' ')
n, x = [int(n),int(x)]
barger = 'P'
for i in range(n):
    barger = 'B'+ barger + 'P' + barger + 'B'
print(barger[len(barger)-x:len(barger)].count('P'))