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:

ans = 0
def count_ans(level, index, len_dic, p_dic):
    global ans
    if level == 0:
        ans += 1
    else:
        if index == 0:
            pass
        if index == len_dic[level] // 2:
            ans += 1
            ans += p_dic[level - 1]
        elif index == len_dic[level] - 1:
            ans += p_dic[level]
        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: Runtime Error

Solution code:

ans = 0
def count_ans(level, index, len_dic, p_dic):
    global ans
    if level == 0:
        ans += 1
    else:
        if index == len_dic[level] // 2:
            ans += 1
            ans += p_dic[level - 1]
        elif index == len_dic[level] - 1:
            ans += p_dic[level]
        elif index == 0:
            pass
        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: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
sou = lambda n: 2 ** (n + 2) - 3
ptn = lambda n: 2 ** (n + 1) - 1


def pate(lv, x):
    if x == 0:
        return 0
    if x < 0:
        return -1
    else:
        for i in range(lv + 1):
            if x < lv - i + sou(i): break
        i -= 1
        re = ptn(i) + 1 + pate(i, x - (lv - i + sou(i) + 1))
        return re


lv, x = map(int, input().split())
print(pate(lv, x))

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <bitset>
#include <map>
#include <string>
#include <utility>

#define repd(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;

int inputValue(){
	int a;
	cin >> a;
	return a;
}

void inputArray(int *p,int a){
	rep(i,a){
		cin >> p[i];
	}
}

void inputVector(vector<int> *p,int a){
	rep(i,a){
		int input;
		cin >> input;
		p -> push_back(input);
	}
}

template <typename T>
void output(T a,int precision){
	if(precision > 0){
		cout << setprecision(precision) << a << "\n";
	}else{
		cout << a << "\n";
	}
}

vector<ll> a,p;
ll f(ll n,ll x){
	if(n==0){
		if(x<=0){
			return 0;
		}else{
			return 1;
		}
	}else if(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]);
	}
}

int main(){
	//source
	ll n,x;
	cin >> n >> x;
	a.push_back(1);
	p.push_back(1);
	rep(i,n){
		a.push_back(a[i]*2+3);
		p.push_back(p[i]*2+1);
	}

	cout << f(n,x) << endl;
	return 0;
}

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

def patty(N,X):
	if N==1:
		l = [0,1,2,3,3]
		return l[X-1]
	elif N>=2:
		if X<(height[N]+1)/2:
			return patty(N-1,X-1)
		elif X==(height[N]+1)/2:
			return patty(N-1,height[N-1]) + 1
		elif X>(height[N]+1)/2:
			return patty(N-1,height[N-1]) + 1 + patty(N-1,X-2-height[N-1])

print(patty(N,X))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, X):
    @lru_cache(maxsize=None)
    def p(n):
        if n == 0:
            return 1
        return 2*p(n-1) + 1
    
    @lru_cache(maxsize=None)
    def a(n):
        if n == 0:
            return 1
        return 2*a(n-1) + 3
    
    def f(n, x):
        if x == 1:
            return 0
        
        elif x < a(n-1) + 1:
            return f(n-1, x-1)

        elif x == a(n-1) + 2:
            return p(n-1) + 1

        elif x < a(n) - 2:
            return p(n) - f(n-1, a(n)-x-1)
        
        else:
            return p(n)
    
    return f(N, X)


def main():
    # N = read_int()
    N, X = read_int_n()
    # A = [read_int_n() for _ in range(N)]
    print(slv(N, X))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

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

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

burger_lvX = str(Burger(N, "P"))

print(burger_lvX[:X].count("P"))

Submission status: Runtime Error

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

hambs = [(1, 0, 1)]
for l in range(1, n+1):
    n_p, n_b, n_l = hambs[l-1]
    hambs.append((2*n_p+1, 2*n_b+2, 2*n_l+3))
# for h in hambs:
#     print(h)

n_p, _, n_l = hambs[n]
if x == 1:
    print(0)
    exit()
elif x == n_l:
    print(n_p)
    exit()
    
ans = n_p//2+1
y = n_l//2+1
l = n-1
while y != x:
    n_p, _, n_l = hambs[l]
    if y > x:
        ans -= n_p
        y -= n_l
    else:
        ans += n_p
        y += n_l
    l -= 1

print(ans)

Submission status: Runtime Error

Solution code:
import math


# def burger_generator(n):
#     if n == 0:
#         return int("101", 2)
#     else:
#         lt = burger_generator(n-1)
#         x1 = 1 + (lt << 1)
#         length = int(math.log2(x1)) + 1
#         x1 = x1 + (lt << length + 1)
#         length = int(math.log2(x1)) + 1
#         return x1 + (1 << length)


def f(N, X):
    if X == 1:
        return 0
    if 1 < X <= 1 + size[N - 1]:
        return f(N - 1, X - 1)
    if X == 2 + size[N]:
        return patty[N - 1] + 1
    if 2 + size[N - 1] < X <= 2 + 2 * size[N - 1]:
        return patty[N - 1] + 1 + f(N - 1, X - 2 - size[N - 1])
    if X == 3 + 2 * size[N - 1]:
        return 2 * patty[N - 1] + 1


N, X = map(int, input().split())
print(N, X)
# burger = format(burger_generator(N), "b")
# print(burger[-K:].count("0"))
size, patty = [1], [1]
for i in range(N):
    size.append(size[i] * 2 + 3)
    patty.append(patty[i] * 2 + 1)

print(f(N, X))

Submission status: Runtime Error

Solution code:
def L(N):
    if N==0:
        return 1
    else:
        prev_L = L(N-1)
        return 1+prev_L+1+prev_L+1
def numP(N):
    if N==0:
        return 1
    else:
        prev_P = numP(N-1)
        return 2*prev_P+1
def eated_P(N,X):
    ans = 0
    fh=int(L(2)/2)
    if X==0:
        return 0
    elif N==0:
        return 1
    elif fh<X:
        ans = numP(N-1)+1+eated_P(N-1,X-fh-1)
        return ans
    else:
        ans = eated_P(N-1,X-N-1)
        return ans
N,X = map(int(), input().split())
print(eated_P(N,X))

Submission status: Runtime Error

Solution code:
#レベルNバーガーを作る。
LEVEL="P" #LEVEL-Zeroの生成
NX=input()
ListNX=NX.split()
N=int(ListNX[0])
X=int(ListNX[1])
for i in range(0,N,1): #LEVEL-Nの生成
  NEXT="B"+str(LEVEL)+"P"+str(LEVEL)+"B"
  LEVEL=str(NEXT)

EATEN=LEVEL[X::-1] #食べる部分の文字列取り出す
Ans=EATEN.count("P")
print(Ans)

Submission status: Runtime Error

Solution code:
#レベルNバーガーを作る。
LEVEL="P" #LEVEL-Zeroの生成
NX=input()
ListNX=NX.split()
N=ListNX[0]
X=ListNX[1]
for i in range(0,N,1): #LEVEL-Nの生成
  NEXT="B"+str(LEVEL)+"P"+str(LEVEL)+"B"
  LEVEL=str(NEXT)

EATEN=LEVEL[X::-1] #食べる部分の文字列取り出す
Ans=EATEN.count("P")
print(Ans)

Submission status: Runtime Error

Solution code:

# coding: utf-8

# In[54]:


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


# In[42]:


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


# In[56]:


def func(i,x):
    if x <= l(i):
        if i == 0:
            if x == 1:
                return 1
            else:
                return 0
        else:
            if x <= 2**(i+1) - 2:
                return func(i-1, x-1)
            else:
                return p(i-1) + 1 + func(i-1, x-(2**(i+1)-2)-1,)


# In[57]:


print(func(n,x))

Submission status: Runtime Error

Solution code:

# coding: utf-8

# In[1]:


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


# In[5]:


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


# In[30]:


def func(i,x):
    if x > l(i):
        print("error")
    else:
        if i == 0:
            if x == 1:
                return 1
            else:
                return 0
        else:
            if x <= 2**(i+1) - 2:
                return func(i-1, x-1)
            else:
                return p(i-1) + 1 + func(i-1, x-(2**(i+1)-2)-1,)


# In[34]:


print(func(n,x))

Submission status: Runtime Error

Solution code:
n, x = input().split()
bg = "P"
for i in range(0, int(n)):
  bg = "B" + bg + "P" + bg + "B"
print(bg[-(int(x)):].count("P"))

Submission status: Runtime Error

Solution code:
# D
N, X = map(int, input().split())
lv = [0]*(N+1)
lv[0] = 'P'
for i in range(1, len(lv)):
    lv[i] = 'B' + lv[i-1] + 'P' + lv[i-1] + 'B'
print(lv[N][-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.append("B"+burger[i-1]+"P"+burger[i-1]+"B")
#print(burger[N])
print(burger[N][0:X].count("P"))

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)
deff(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())
a,p=[1],[1] for i in range(N):
    a.append(a[i] * 2 + 3)
    p.append(p[i] * 2 + 1)
deff(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())
def a(n):
    if n==0:
        return 1
    else:
        return a(n-1)*2+3
def p(n):
    if n==0:
        return 1
    else:
        return p(n-1)*2+1
def f(n,x):
    if x==0:
        return 0
    if 0<x<=a(n-1)+1:
        return f(n-1,x-1)
    if x==a(n-1)+2:
        return 1+p(n-1)
    if a(n-1)+2<x<=a(n-1)*2+2:
        return 1+p(n-1)+f(n-1,x-a(n-1)-2)
    if x==2*a(n-1)+3:
        return p(n)
print(f(N,X))

Submission status: Runtime Error

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

b_str = "1"
for i in range(n):
    b_str = "0" + b_str + "1" + b_str + "0"

print(b_str[:x].count("1"))

Submission status: Runtime Error

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

#print("N , X = " + str(N) + str(X))

count = 0

L = ["P"]

for n in range(N):
	L.append("B" + str(L[n]) + "P" + str(L[n]) + "B")

#print("L = " + str(L))

#print(L[N][:X+1])
for i in range(X):
	if L[N][i:i+1] == "P":
		count +=1

print(count)

Submission status: Runtime Error

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

def calc(N, X):
    if X == 0:
        return 0

    Y = 2 ** (N + 1) - 1
    if X == Y:
        return 2 ** N
    elif X == Y - 1:
        return 2 ** N - 1
    elif X < Y - 1:
        return calc(N - 1, X - 1)
    else:
        return 2 ** (N + 1) - 1 - calc(N - 1, 2 ** (N + 2) - 4 - X)

def main():
    [N, X] = list(map(int, input().split()))

    r = calc(N, X)


    print(r)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
nk_list = list(map(int, input().split()))
n,k = nk_list[0], nk_list[1]

keta_lst = list()
for i in range(50):
    if i == 0:
        keta = 1
        keta_lst.append(keta)
    else:
        keta = 2*keta + 3
        keta_lst.append(keta)

paty_lst = list()
for i in range(50):
    if i == 0:
        paty = 1
        paty_lst.append(paty)
    else:
        paty = 2*paty+1
        paty_lst.append(paty)

def eat_paty(n,k):
    
    if n == 0 and k == 1:
        return 1
    
    keta_before = keta_lst[n-1]
    
    if k == 1:
        return 0
    elif k <= keta_before + 1:
        return eat_paty(n-1, k-1)
    elif k == keta_before + 2:
        return paty_lst[n-1]+1
    elif k <= 2*keta_before + 1:
        return paty_lst[n-1] + 1 + eat_paty(n-1, k-keta_before-2)
    elif k == 2*keta_before + 2:
        return 2 * paty_lst[n-1] + 1

print(eat_paty(n,k))

Submission status: Runtime Error

Solution code:
nk_list = list(map(int, input().split()))
n,k = nk_list[0], nk_list[1]

keta_lst = list()
for i in range(50):
    if i == 0:
        keta = 1
        keta_lst.append(keta)
    else:
        keta = 2*keta + 3
        keta_lst.append(keta)

paty_lst = list()
for i in range(50):
    if i == 0:
        paty = 1
        paty_lst.append(paty)
    else:
        paty = 2*paty+1
        paty_lst.append(paty)

def eat_paty(n,k):
    
    if n == 0 and k == 1:
        return 1
    
    keta_before = keta_lst[n-1]
    
    if k == 1:
        return 0
    elif k <= keta_before + 1:
        return eat_paty(n-1, k-1)
    elif k == keta_before + 2:
        return paty_lst[n-1]
    elif k <= 2*keta_before + 1:
        return paty_lst[n-1] + eat_paty(n-1, k-keta_before-2)
    elif k == 2*keta_before + 2:
        return 2 * paty_lst[n-1]

print(eat_paty(n,k))

Submission status: Runtime Error

Solution code:
h=[]
h.append("P")

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

for i in range(1,n+1):
  h.append("B"+h[i-1]+"P"+h[i-1]+"B")
  #print (h[i])
  
taberu=h[n][0:x]
print(taberu.count("P"))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

c = a[1]
res = 0

b = [[5,3,1]]
for i in range(1,a[0]+1):
    tmp = [b[i-1][0]*2+3,b[i-1][1]*2+1,i+1]
    b.append(tmp)

for i in range(50-1,0,-1):
    c = c - 1
    if b[i][0] < c:
        c = c - b[i][0] - 1
        res = res + b[i][1] + 1
if c == 1:
    res = res + 1

print(res)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
# coding: utf-8

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

patti=0
burger="P"

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

for i in range(x):
    if burger[i]=="P":
        patti+=1

print(patti)

Submission status: Runtime Error

Solution code:
memo = {}

def _burger(level):
  if level == 0:
    return 'P'
  if level == 1:
    return 'BPPPB'
  else:
    if level not in memo:
      memo[level] = 'B' + _burger(level - 1) + 'P' + _burger(level - 1) + 'B'
    return memo[level]
    

N, X = [int(s) for s in input().split(' ')]

burger = _burger(N)

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

Submission status: Runtime Error

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

index = ['P'] * (N+1)
for i in range(N):
    index[i+1] = 'B' + index[i] + 'P' + index[i] + 'B'

count = 0
for x in range(X):
    if index[N][-x-1] == 'P':
        count += 1
        
print(count)

Submission status: Runtime Error

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

burger = "P"

for i in range(N):
    burger = "B" + burger + "P" + burger + "B"

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

Submission status: Runtime Error

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

a,p=[1],[1]
for i in range(n):
	a.append(a[i]*2+3)
	p.append(p[i]*2+1)

def f(n,x):
	if n==0:
		return0 if x<=0 else 1
	elif x<=1+a[n-1]:
		return f(n-1,x-1)
	else:
		return p[n-1]+1+f(n-1,x-2-a[n-1])

print(f(n,x))

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

A = ['P']

for i in range(1, n+1):
    A.append('B'+A[i-1]+'P'+A[i-1]+'B')

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

Submission status: Runtime Error

Solution code:
n=int(input())
x=int(input())
list=['P']
i=1
while i<n+1:
    list.append('P')
    list=list + list
    list.pop()
    list.append('B')
    list.insert(0,'B')
    i +=1
sosu=len(list)
ku=sosu - x
i=1
while i<ku+1:
    list.pop()
    i +=1
print(list.count('P'))

Submission status: Runtime Error

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

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

# レベルLバーガーの厚さ, レベルLバーガーに含まれるパティの数
thick, patti = [1], [1]
for i in range(N):
    thick.append(2 * thick[-1] + 3)
    patti.append(2 * patti[-1] + 1)


def solve(n, x):
    if x == 1:  # 一番下のバン(ただしレベル0バーガー参照時には+1)
        return 0 + (n == 0)

    # 一番下のバン + レベルL-1バーガーの途中まで
    elif 1 < x <= 1 + thick[n - 1]:
        return solve(n - 1, x - 1)

    # 一番下のバン + レベルL-1バーガー + 真ん中のパティ + レベルL-1バーガーの途中まで + (どうでもいい最後のバン)
    else:
        return patti[n - 1] + 1 + solve(n - 1, x - 1 - thick[n - 1] - 1)


print(solve(N, X))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

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

    if x == 1:
        return 0
    elif x > 1 and x <= counts[n-1] + 1:
        return req(n - 1, x - 1)
    elif x == counts[n-1] + 2:
        return req(n - 1, counts[n-1]) + 1
    elif x > counts[n-1] + 2:
        if x == 2*counts[n-1] + 3:
            return req(n-1, counts[n-1])*2+1
        else:
            return req(n-1, x - (counts[n-1] + 2) - 1) + req(n - 1, counts[n-1])


print(req(N, X))

Submission status: Runtime Error

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

def tlen(L):
    l = 1
    for i in range(1, L):
        l = l*2 + 3
    return l

def tpat(L):
    p = 1
    for i in range(1, L):
        p = p*2 + 1
    return p

def maisu(n, x):
    tl = tlen(n)
    if x == 1:
        return(0)
    elif n == 1:
        b = "bpppb"
        b = b[:x]
        return(b.count(p))
    elif 2 <= x <= 1+tl-1:
        return(maisu(n-1, x-1))
    elif x == 1+tl:
        return(tpat(n))
    elif x == 2+tl:
        return(tpat(n)+1)
    elif tl+3 <= x <= 1+tl*2:
        return(tpat(n)+1+maisu(n-1,x-2-tl))
    else:
        return(tpat(n)*2+1)  

print(maisu(n,x))

Submission status: Runtime Error

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


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


def ai(n):
    return 2**(n+2) - 3


def f(n, x):
    if N == 0:
        return 0 if X <= 0 else 1
    elif (1 < x) and (x <= 1 + ai(n-1)):
        return f(n - 1, x - 1)
    elif x == 2 + ai(n - 1):
        return pi(n - 1) + 1
    elif (2 + ai(n - 1) < x) and (x <= 2 + 2 * ai(n - 1)):
        return pi(n-1) + 1 + f(n-1, x-2-ai(n-1))
    elif x >= ai(n):
        return pi(n)


print(f(n, x))

Submission status: Runtime Error

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


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


def ai(n):
    if n == 1:
        return 5
    return 2*ai(n-1) + 3


def f(n, x):
    if x == 1:
        return 0
    elif (1 < x) and (x <= 1 + ai(n-1)):
        return f(n - 1, x - 1)
    elif x == 2 + ai(n - 1):
        return pi(n - 1) + 1
    elif (2 + ai(n - 1) < x) and (x <= 2 + 2 * ai(n - 1)):
        return pi(n-1) + 1 + f(n-1, x-2-ai(n-1))
    elif x == ai(n):
        return pi(n)


print(f(n, x))

Submission status: Runtime Error

Solution code:
def make(N):
  if N == 0:
    return "p"
  else:
    e = make(N-1)
    return "b" + e + "p" + e + "b"

N,x = map(int,input().split())
Sum = 0
s = make(N)

for i in range(0,x):
  if(s[i] == "p"):
    Sum += 1

print (Sum)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

def makeBurger(s):
    return "B"+s+"P"+s+"B"
s = "P"
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: Runtime Error

Solution code:
n,x = map(int,input().split())
  
a,b = [1],[1]
for i in range(n):
  a.append(a[i]*2+3)
  b.append(b[i]*2+1)
  
  
def makeburger(n,x):
  if x == 1:
    return 0
  elif x <=1+a[n-1]:  #x層が半分以下の時
    return makeburger(n-1,x-1)
   
  else:
    return b[n-1]+1+makeburger(n-1,x-2-a[n-1])
  
print(makeburger(n,x))