Problem:


Score : 400 points

Problem Statement

In some other world, today is Christmas.

Mr. Takaha decides to make a multi-dimensional burger in his party. A level-L burger (L is an integer greater than or equal to 0) is the following thing:

A level-0 burger is a patty.

A level-L burger (L \geq 1) is a bun, a level-(L-1) burger, a patty, another level-(L-1) burger and another bun, stacked vertically in this order from the bottom.

For example, a level-1 burger and a level-2 burger look like BPPPB and BBPPPBPBPPPBB (rotated 90 degrees), where B and P stands for a bun and a patty.

The burger Mr. Takaha will make is a level-N burger. Lunlun the Dachshund will eat X layers from the bottom of this burger (a layer is a patty or a bun). How many patties will she eat?

Constraints

1 \leq N \leq 50

1 \leq X \leq ( the total number of layers in a level-N burger )

N and X are integers.

Input

Input is given from Standard Input in the following format:

N X

Output

Print the number of patties in the bottom-most X layers from the bottom of a level-N burger.

Sample Input 1

2 7

Sample Output 1

4

There are 4 patties in the bottom-most 7 layers of a level-2 burger (BBPPPBPBPPPBB).

Sample Input 2

1 1

Sample Output 2

0

The bottom-most layer of a level-1 burger is a bun.

Sample Input 3

50 4321098765432109

Sample Output 3

2160549382716056

A level-50 burger is rather thick, to the extent that the number of its layers does not fit into a 32-bit integer.



Sample input:
2 7


Sample output:
4

Submission status: Wrong Answer

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

layers, patties = [1],[1]
for i in range(n):
    layers.append(layers[-1] * 2 + 3)
    patties.append(patties[-1] * 2 + 1)

def solve(cur, level):
    if level == 0:
        return 1 if cur == 1 else 0
    elif (layers[level] // 2) >= cur:
        return solve(cur - 1, level - 1)
    else:
        return solve(cur - layers[level-1] - 2, level - 1) + patties[level-1] + 1

print(solve(x,n))

Submission status: Wrong Answer

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

layers, patties = [1],[1]
for i in range(n):
    layers.append(layers[-1] * 2 + 3)
    patties.append(patties[-1] * 2 + 1)

def solve(cur, level):
    if level == 0:
        return 1 if cur == 1 else 0
    elif (layers[level] // 2) + 1 >= cur:
        return solve(cur - 1, level - 1)
    else:
        return solve(cur - layers[level-1] - 2, level - 1) + patties[level-1] + 1

print(solve(x,n))

Submission status: Wrong Answer

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

layers, patties = [1],[1]
for i in range(n):
    layers.append(layers[-1] * 2 + 3)
    patties.append(patties[-1] * 2 + 1)

def solve(cur, level):
    if level == 0:
        return 1 if cur == 1 else 0
    elif (layers[level] // 2) + 1 > cur:
        return solve(cur - 1, level - 1)
    else:
        return solve(cur - layers[level-1] - 2, level - 1) + patties[level-1] + 1

print(solve(x,n))

Submission status: Wrong Answer

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

layers, patties = [1],[1]
for i in range(n):
    layers.append(layers[-1] * 2 + 3)
    patties.append(patties[-1] * 2 + 1)

def solve(cur, level):
    if level == 0:
        return 1 if cur == 1 else 0
    elif (layers[level] // 2) > cur:
        return solve(cur - 1, level - 1)
    else:
        return solve(cur - layers[level-1] - 2, level - 1) + patties[level-1] + 1

print(solve(x,n))

Submission status: Wrong Answer

Solution code:
Tmp = []
Tmp = input().rstrip().split(' ')
 
nN = int(Tmp[0])
nX = int(Tmp[1])


nA = 1
nP = 1
 
nAnsA = []
nAnsP = []

nAnsA.append(1)
nAnsP.append(1)
 
for i in range(nN):
  nTmpA = nA * 2 +3
  nTmpP = nP * 2 +1
  nAnsA.append(nTmpA)
  nAnsP.append(nTmpP)
  nA = nTmpA
  nP = nTmpP

nAnsA.sort(reverse=True)  
nAnsP.sort(reverse=True)  
nN += 1

nMaxA = nAnsA[0]
nMaxP = nAnsP[0]
 
nTmpA = nMaxA
nTmpP = nMaxP
 
nAns = 0

# print(nAnsA)
# print(nAnsP)


for i in range(nN):
#  print(nX)
  if i == nN - 1:
    nAns += 1
    break
  else:
    nTmpA = nAnsA[i+1] + 2
    nTmpP = nAnsP[i+1] + 1
#  print(nTmpA)
#  print(nTmpP)

  
  if nTmpA > nX:
    nX -= 1
  elif nTmpA == nX:
    nAns += nTmpP
    break
  elif nTmpA < nX:
    nAns += nTmpP
    nX -= nTmpA
#  print(nAns)
    
print(nAns)

Submission status: Wrong Answer

Solution code:
Tmp = []
Tmp = input().rstrip().split(' ')
 
nN = int(Tmp[0])
nX = int(Tmp[1])
 
nA = 1
nP = 1
 
nAnsA = []
nAnsP = []
 
for i in range(nN):
  nTmpA = nA * 2 +3
  nTmpP = nP * 2 +1
  nAnsA.append(nTmpA)
  nAnsP.append(nTmpP)
  nA = nTmpA
  nP = nTmpP

nAnsA.sort(reverse=True)  
nAnsP.sort(reverse=True)  
  
nMaxA = nAnsA[0]
nMaxP = nAnsP[0]
 
nTmpA = nMaxA
nTmpP = nMaxP
 
nAns = 0
for i in range(nN):
  nTmpA = nAnsA[i] // 2 + 1
  nTmpP = nAnsP[i] // 2 + 1
  
  if nTmpA > nX:
    nX -= 1
  elif nTmpA == nX:
    nAns += nTmpP
    break
  else:
    nAns += nTmpP
    nX -= nTmpA
    
print(nAns)

Submission status: Wrong Answer

Solution code:
Tmp = []
Tmp = input().rstrip().split(' ')
 
nN = int(Tmp[0])
nX = int(Tmp[1])
 
nA = 1
nP = 1
 
nAnsA = []
nAnsP = []
 
for i in range(nN):
  nTmpA = nA * 2 +3
  nTmpP = nP * 2 +1
  nAnsA.append(nTmpA)
  nAnsP.append(nTmpP)
  nA = nTmpA
  nP = nTmpP

nAnsA.sort(reverse=True)  
nAnsP.sort(reverse=True)  
  
nMaxA = nAnsA[0]
nMaxP = nAnsP[0]
 
nTmpA = nMaxA
nTmpP = nMaxP
 
nAns = 0
for i in range(nN):
  nTmpA = nTmpA // 2 + 1
  nTmpP = nTmpP // 2 + 1
  
  if nTmpA > nX:
    nTmpA -= 2
    nTmpP -= 1
    nX -= 1
  elif nTmpA == nX:
    nAns += nTmpP
    break
  else:
    nAns += nTmpP
    nX -= nTmpA
    nTmpA -= 2
    nTmpP -= 1
    
print(nAns)

Submission status: Wrong Answer

Solution code:
Tmp = []
Tmp = input().rstrip().split(' ')
 
nN = int(Tmp[0])
nX = int(Tmp[1])
 
nA = 1
nP = 1
 
nAnsA = []
nAnsP = []
 
for i in range(nN):
  nTmpA = nA * 2 +3
  nTmpP = nP * 2 +1
  nAnsA.append(nTmpA)
  nAnsP.append(nTmpP)
  nA = nTmpA
  nP = nTmpP

nAnsA.sort(reverse=True)  
nAnsP.sort(reverse=True)  
  
nMaxA = nAnsA[0]
nMaxP = nAnsP[0]

nTmpA = nMaxA
nTmpP = nMaxP

nAns = 0
for i in range(nN):
  nTmpA = nTmpA // 2 + 1
  nTmpP = nTmpP // 2 + 1
  
  if nTmpA > nX:
    nTmpA -= 2
    nTmpP -= 1
    nX -= 1
  elif nTmpA == nX:
    nAns += nTmpP
    break
  else:
    nAns += nTmpP
    nX -= nTmpA
    
print(nAns)

Submission status: Wrong Answer

Solution code:
Tmp = []
Tmp = input().rstrip().split(' ')

nN = int(Tmp[0])
nX = int(Tmp[1])

nA = 1
nP = 1

nAnsA = []
nAnsP = []

for i in range(nN):
  nTmpA = nA * 2 +3
  nTmpP = nP * 2 +1
  nAnsA.append(nTmpA)
  nAnsP.append(nTmpP)
  nA = nTmpA
  nP = nTmpP
  
print(nAnsA)

Submission status: Wrong Answer

Solution code:
def main():

    """ convenient functions
    # for i, a in enumerate(iterable)
    # q, mod = divmod(a, b)
    # divmod(x, y) returns the tuple (x//y, x%y)
    # Higher-order function: reduce(operator.mul, xyz_count, 1)
    # manage median(s) using two heapq https://atcoder.jp/contests/abc127/tasks/abc127_f
    """

    """convenient decorator
    # @functools.lru_cache():
    # to facilitate use of recursive function
        # ex:
        # from functools import lru_cache
        # import sys
        # sys.setrecursionlimit(10**9)
        # @lru_cache(maxsize=None)
        # def fib(n):
        #     if n < 2:
        #         return n
        #     return fib(n-1) + fib(n-2)
        # print(fib(1000))
    """
    
    # import numpy as np
    import sys
    sys.setrecursionlimit(10**7)
    from itertools import accumulate, combinations, permutations, product # https://docs.python.org/ja/3/library/itertools.html
    # accumulate() returns iterator! to get list: list(accumulate())
    from math import factorial, ceil, floor, sqrt
    def factorize(n):
        """return the factors of the Arg and count of each factor
        
        Args:
            n (long): number to be resolved into factors
        
        Returns:
            list of tuples: factorize(220) returns [(2, 2), (5, 1), (11, 1)]
        """
        fct = []  # prime factor
        b, e = 2, 0  # base, exponent
        while b * b <= n:
            while n % b == 0:
                n = n // b
                e = e + 1
            if e > 0:
                fct.append((b, e))
            b, e = b + 1, 0
        if n > 1:
            fct.append((n, 1))
        return fct
    def combinations_count(n, r):
        """Return the number of selecting r pieces of items from n kinds of items.
        
        Args:
            n (long): number
            r (long): number
        
        Raises:
            Exception: not defined when n or r is negative
        
        Returns:
            long: number
        """
        # TODO: How should I do when n - r is negative?
        if n < 0 or r < 0:
            raise Exception('combinations_count(n, r) not defined when n or r is negative')
        if n - r < r: r = n - r
        if r < 0: return 0
        if r == 0: return 1
        if r == 1: return n
        numerator = [n - r + k + 1 for k in range(r)]
        denominator = [k + 1 for k in range(r)]
        for p in range(2,r+1):
            pivot = denominator[p - 1]
            if pivot > 1:
                offset = (n - r) % p
                for k in range(p-1,r,p):
                    numerator[k - offset] /= pivot
                    denominator[k] /= pivot
        result = 1
        for k in range(r):
            if numerator[k] > 1:
                result *= int(numerator[k])
        return result
    def combinations_with_replacement_count(n, r):
        """Return the number of selecting r pieces of items from n kinds of items allowing individual elements to be repeated more than once.
        
        Args:
            n (long): number
            r (long): number
        
        Raises:
            Exception: not defined when n or r is negative
        
        Returns:
            long: number
        """
        if n < 0 or r < 0:
            raise Exception('combinations_with_replacement_count(n, r) not defined when n or r is negative')
        elif n == 0:
            return 1
        else:
            return combinations_count(n + r - 1, r)
    from bisect import bisect_left, bisect_right
    from collections import deque, Counter, defaultdict # https://docs.python.org/ja/3/library/collections.html#collections.deque
    from heapq import heapify, heappop, heappush, heappushpop, heapreplace,nlargest,nsmallest # https://docs.python.org/ja/3/library/heapq.html
    from copy import deepcopy, copy # https://docs.python.org/ja/3/library/copy.html
    import operator
    from operator import itemgetter #sort 
    # ex1: List.sort(key=itemgetter(1))
    # ex2: sorted(tuples, key=itemgetter(1,2))
    from functools import reduce, lru_cache
    def chmin(x, y):
        """change minimum
        if x > y, x = y and return (x, True).
        convenient when solving problems of dp[i]
        
        Args:
            x (long): current minimum value
            y (long): potential minimum value
        
        Returns:
            (x, bool): (x, True) when updated, else (x, False)
        """
        if x > y:
            x = y
            return (x, True)
        else:
            return (x, False)
    def chmax(x, y):
        """change maximum
        if x < y, x = y and return (x, True).
        convenient when solving problems of dp[i]
        
        Args:
            x (long): current maximum value
            y (long): potential maximum value
        
        Returns:
            (x, bool): (x, True) when updated, else (x, False)
        """
        if x < y:
            x = y
            return (x, True)
        else:
            return (x, False)

    from fractions import gcd # Deprecated since version 3.5: Use math.gcd() instead.
    def gcds(numbers):
        return reduce(gcd, numbers)
    def lcm(x, y):
        return (x * y) // gcd(x, y)
    def lcms(numbers):
        return reduce(lcm, numbers, 1)

    # first create factorial_list
    # fac_list = mod_factorial_list(n)
    INF = 10 ** 18
    MOD = 10 ** 9 + 7
    modpow = lambda a, n, p = MOD: pow(a, n, p) # Recursive function in python is slow!
    def modinv(a, p = MOD):
        # evaluate reciprocal using Fermat's little theorem:
        # a**(p-1) is identical to 1 (mod p) when a and p is coprime
        return modpow(a, p-2, p)
    def modinv_list(n, p = MOD):
        if n <= 1:
            return [0,1][:n+1]
        else:
            inv_t = [0,1]
            for i in range(2, n+1):
                inv_t += [inv_t[p % i] * (p - int(p / i)) % p]
            return inv_t
    def modfactorial_list(n, p = MOD):
        if n == 0:
            return [1]
        else:
            l = [0] * (n+1)
            tmp = 1
            for i in range(1, n+1):
                tmp = tmp * i % p
                l[i] = tmp
            return l
    def modcomb(n, k, fac_list = [], p = MOD):
        # fac_list = modfactorial_list(100)
        # print(modcomb(100, 5, modfactorial_list(100)))
        from math import factorial
        if n < 0 or k < 0 or n < k: return 0
        if n == 0 or k == 0: return 1
        if len(fac_list) <= n:
            a = factorial(n) % p
            b = factorial(k) % p
            c = factorial(n-k) % p
        else:
            a = fac_list[n]
            b = fac_list[k]
            c = fac_list[n-k]
        return (a * modpow(b, p-2, p) * modpow(c, p-2, p)) % p
    def modadd(a, b, p = MOD):
        return (a + b) % MOD
    def modsub(a, b, p = MOD):
        return (a - b) % p
    def modmul(a, b, p = MOD):
        return ((a % p) * (b % p)) % p
    def moddiv(a, b, p = MOD):
        return modmul(a, modpow(b, p-2, p))

    class UnionFindTree:
        """union find tree class
        TODO: fix this description...
        how to use (example):
        >>  uf = UnionFindTree(N) 
        >>  if uf.find_root(a) == uf.find_root(b):
        >>      do something
        >>  else:
        >>      do something
        >>      uf.unite(a, b)
        """
        def __init__(self, N):
            self.root = [-1] * (N+1)
            self.rank   = [0]  * (N+1)
            self.connected_num = [1] * (N+1)
    
        def find_root(self,x):
            root = self.root
            while root[x] != -1:
                x = root[x]
            return x
    
        def unite(self,x,y):
            root = self.root
            rank = self.rank
            connected_num = self.connected_num
            find_root = self.find_root
    
            rx = find_root(x)
            ry = find_root(y)
            if rx != ry:
                if rank[rx] < rank[ry]:
                    root[rx] = ry
                    rx,ry = ry,rx
                else:
                    if rank[rx] == rank[ry]:
                        rank[rx] += 1
                    root[ry] = rx       
                connected_num[rx] += connected_num[ry]

    """ initialize variables and set inputs
    # initialize variables
        # to initialize list, use [0] * n
        # to initialize two dimentional array, use [[0] * N for _ in range(N)]
    # set inputs
        # put inputs between specific values (almost as quickly)
        # ex) S = [-INF] + [int(r()) for _ in range(A)] + [INF]
        # open(0).read() is sometimes useful:
        # ex) n, m, *x = map(int, open(0).read().split())
        #     min(x[::2]) - max(x[1::2])
        # ex2) *x, = map(int, open(0).read().split())
        #     don't forget to add comma after *x if only one variable is used
    # preprocessing
        # transpose = [x for x in zip(*data)]
        # ex) [[1, 2, 3], [4, 5, 6], [7, 8, 9]] => [(1, 4, 7), (2, 5, 8), (3, 6, 9)]
        # flat = [flatten for inner in data for flatten in inner]
        # ex) [[1, 2, 3], [4, 5, 6], [7, 8, 9]] => [1, 2, 3, 4, 5, 6, 7, 8, 9]
    # calculate and output
        # output pattern
        # ex1) print(*l) => when l = [2, 5, 6], printed 2 5 6
    """

    # functions used
    r = lambda: sys.stdin.readline().strip()
    r_int = lambda: int(r())
    R = lambda: list(map(int, r().split()))
    Rmap = lambda: map(int, r().split())
    Rfloat = lambda: list(map(float, r().split()))
    Rtuple = lambda: tuple(map(int, r().split()))

    """ how to treat input
    # single int: int(r())
    # single string: r()
    # single float: float(r())
    # line int: R()
    # line string: r().split()
    # line (str, int, int): [j if i == 0 else int(j) for i, j in enumerate(r().split())]
    # lines int: [R() for _ in range(n)]
    """

    if __name__ != '__main__':
        # for test
        sys.stdin = open('sample.txt')
        
    # ----------------------------------
    # main

    N, X = R()
    """
    A_n = 2A_(n-1) + 3, A_0 = 1
    B_n = 2B_n-1 + 1, B_0 = 0
    """
    A = [1] * 50
    B = [0] * 50
    for i in range(1, 50):
        A[i] = 2 * A[i-1] + 3
    for i in range(1, 50):
        B[i] = 2 * B[i-1] + 1
    @lru_cache(maxsize=None)
    def burg(l, x):
        if x == 1:
            return 0
        elif x <= 1 + A[l-1]:
            return 0 + burg(l-1, x-1)
        elif x == 2 + A[l-1]:
            return 1 + B[l-1]
        elif x <= 2 + 2*A[l-1]:
            return 1 + B[l-1] + burg(l-1, x-2-A[l-1])
        else:
            return 1 + 2*B[l-1]
    print(2*burg(N, X))
    
    # def burger(l):
    #     if l == 0:
    #         return 'P'
    #     else:
    #         return 'B' + burger(l-1) + 'P' + burger(l-1) + 'B'
    # print(burger(3))
    
    # end of main
    # ----------------------------------

    """memo: how to use defaultdict of list
    # initialize
    Dic = defaultdict(list)
    # append / extend
    Dic[x].append(y)
    # three methods for loop: keys(), values(), items()
    for k, v in Dic.items():
    """
    
    """memo: how to solve binary problems
    # to make binary digits text
    >>> a = 5
    >>> bin_str_a = format(a, '#06b')
    >>> print(bin_str_a)
    0b0101 # first 2 strings (='0b') indicates it is binary
    """
    
    """memo: how to solve the problem
    creating simple test/answer
    greed
    simple dp
    graph
    """

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

burger_list = []
for i in range(N+1):
    if i == 0:
        burger_list.append([0,1])
    else:
        burger_list.append([2+burger_list[-1][0]*2,1+burger_list[-1][1]*2])

def pty(x,k,List):
    if x == 1:
        y = 0
    elif 1 < x <= sum(List[k-1])+1:
        y = 1
    elif x == 2+sum(List[k-1]):
        y = 2
    elif x == sum(List[k]):
        y = 4
    elif 2+sum(List[k-1]) < x <= 2+sum(List[k-1])*2:
        y = 3
    return y
        
ans = 0
k = N
while X > 0:
    n = pty(X,k,burger_list)
    if n == 0:
        X = 0
    elif n == 2:
        ans += (burger_list[k-1][1]+1)
        X = 0
    elif n == 4:
        ans += burger_list[k][1]
        X = 0
    elif n == 1:
        X -= 1
        k -= 1
    elif n == 3:
        ans += (burger_list[k-1][1]+1)
        X -= (sum(burger_list[k-1])+2)
        k -= 1
        
print(ans)

Submission status: Wrong Answer

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

burger_list = []
for i in range(N+1):
    if i == 0:
        burger_list.append([0,1])
    else:
        burger_list.append([2+burger_list[-1][0]*2,1+burger_list[-1][1]*2])

def pty(x,k,List):
    if x == 1:
        y = 0
    elif 1 < x <= sum(List[k-1])+1:
        y = 1
    elif x == 2+sum(List[k-1]):
        y = 2
    elif x == sum(List[k]):
        y = 4
    else:
        y = 3
    return y
        
ans = 0
k = N
while X > 0:
    n = pty(X,k,burger_list)
    if n == 0:
        X = 0
    elif n == 2:
        ans += (burger_list[k-1][1]+1)
        X = 0
    elif n == 4:
        ans += burger_list[k][1]
        X = 0
    elif n == 1:
        X -= 1
        k -= 1
    else:
        ans += (burger_list[k-1][1]+1)
        X -= (sum(burger_list[k-1])+2)
        k -= 1
        
print(ans)

Submission status: Wrong Answer

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

burger_list = []
for i in range(N+1):
    if i == 0:
        burger_list.append([0,1])
    else:
        burger_list.append([2+burger_list[-1][0]*2,1+burger_list[-1][1]*2])

def pty(x,k,List,N):
    if x == 1:
        y = 0
    elif 1 < x <= sum(List[k-1])+1:
        y = 1
    elif x == 2+sum(List[k-1]):
        y = 2
    elif x == sum(List[k]):
        y = 4
    else:
        y = 3
    return y
        
ans = 0
k = N
while X > 0:
    n = pty(X,k,burger_list,N)
    if n == 0:
        X = 0
    elif n == 2:
        ans += (burger_list[k-1][1]+1)
        X = 0
    elif n == 4:
        ans += burger_list[k][1]
        X = 0
    elif n == 1:
        X -= 1
        k -= 1
    else:
        ans += (burger_list[k-1][1]+1)
        X -= (sum(burger_list[k-1])+2)
        k -= 1
        
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

def calc(N, X): #レベルNバーガーの下からX層に含まれるパティの枚数
    if N == 0: #全てパティ
        if X == 0:
            return 0
        else:
            return 1
    if X == 1:
        return 0
    # print (N - 1)
    if 1 < X <= 1 + a[N - 1]:
        print ('A')
        return calc(N - 1, X - 1)
    if X == 2 + a[N - 1]:
        # print ('B')
        return p[N - 1] + 1
    if 2 + a[N - 1] < X <= 2 + 2 * a[N - 1]:
        # print ('C')
        return p[N - 1] + 1 + calc(N - 1, max(X - 2 - a[N - 1], 0))
    if X == 3 + 2 * a[N - 1]:
        # print ('D')
        return p[N]

print (calc(N, X))

Submission status: Wrong Answer

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

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

def calc(N, X): #レベルNバーガーの下からX層に含まれるパティの枚数
    if N == 0: #全てパティ
        if X == 0:
            return 0
        else:
            return 1
    if X == 1:
        return 0
    # print (N - 1)
    if 1 < X <= 1 + a[N - 1]:
        # print ('A')
        return calc(N - 1, X - 1)
    if X == 2 + a[N - 1]:
        # print ('B')
        return p[N - 1] + 1
    if 2 + a[N - 1] < X <= 2 + 2 * a[N - 1]:
        # print ('C')
        return p[N - 1] + 1 + calc(N - 1, max(X - 2 - a[N - 1], 0))
    if X == 3 + 2 * a[N - 1]:
        # print ('D')
        return 2 * p[N - 1] + 1

print (calc(N, X))

Submission status: Wrong Answer

Solution code:
import numpy as np

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

# print(size)
def num_p(x,n):
    if n == 0:
        return 1
    burg = size[n-1]
    if x == 1:
        return 0
    elif x == burg+2:
        return full_p[n-1]+1
    elif x < burg +2:
        return num_p(x-1,n-1)
    elif x > burg+2:
        return full_p[n-1]+1+num_p(x-(burg+3),n-1)

# print(size)
ans = num_p(x,n)

print(ans)

Submission status: Wrong Answer

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

    elif X == 1:
        return 0

    elif X <= a[i-1]:
        return f(i-1, X-1)

    elif X == 2 + a[i-1]:
        return p[i-1] + 1

    elif X < a[i]:
        return f(i-1, X-2-a[i-1]) + 1 + p[i-1]

    else:
        return p[i]

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)

print(f(N, X))

Submission status: Wrong Answer

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

    if X == 1:
        return 0

    elif 1 < X <= 1 + a[N-1]:
        return f(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 p[N-1] + 1 + f(N-1, X-2-a[N-1])

    else:
        return 2 * p[N-1] + 1

N, X = map(int, input().split())
a = [1]
p = [1]

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

print(f(N, X))

Submission status: Wrong Answer

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

    if X < 2:
        return 0

    elif 1 < X <= 1 + a[N-1]:
        return f(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 p[N-1] + 1 + f(N-1, X-2-a[N-1])

    else:
        return 2 * p[N-1] + 1

N, X = map(int, input().split())
a = [1]
p = [1]

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

print(f(N, X))

Submission status: Wrong Answer

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

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

burger = [0]*(n+1)#厚み
p = [0]*(n+1)#パテの数
burger[0],p[0] = 1,1
for i in range(n):
    p[i+1] = 2*p[i]+1
    burger[i+1] = 2*burger[i]+3

def f(n,x):
    if x == 1:
        return 0
    elif x <= burger[n-1] + 1:
        return f(n-1,x-1)
    elif x == burger[n-1] + 2:
        return p[n-1] + 1
    elif burger[n-1] + 2 < x <= 2*burger[n-1] + 2:
        return p[n-1] + 1 + f(n-1,x-2-burger[n-1])
    elif x == 2*burger[n-1] + 3:
        return 2*p[n-1] + 1
ans = f(n,x)
print(ans)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
burger=[None]*n
burger[0]="P"
for i in range(1,n):
  burger[i]="B"+burger[i-1]+"P"+burger[i-1]+"B"
print(sum(1 for i in burger[-1][:k] if i=="P"))

Submission status: Wrong Answer

Solution code:
def thickness(l):
    return 2 ** (l + 2) - 3


def pate(l):
    return 2 ** (l + 1) - 1


def rec(l, x):
    t = thickness(l-1)
    if x <= 1:
        return 0
    elif x <= t + 1:
        return rec(l-1, x-1)
    elif x <= t + 2:
        return pate(l-1) + 1
    elif x <= 2 * t + 2:
        return pate(l-1) + 1 + rec(l-1, x-t-2)
    else:
        return pate(l)


def main():
    n, x = map(int, input().split())
    print(rec(n, x))


main()

Submission status: Wrong Answer

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


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

print(f(n,x))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def burger(n, x):
    if x < 1 or x > size[n]:
        return 0

    # base case
    if (n, x) == (0, 1):
        return 1

    if x <= 1 + size[n - 1]:
        return burger(n - 1, x - 1)
    else:
        return p_num[n - 1] + 1 + burger(n - 1, x - 2 - size[n - 1])


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

print(burger(n, x))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict


def burger(n, x):
    if d[(n, x)] >= 0:
        return d[(n, x)]

    if x < 1 or x > size[n]:
        res = 0
        d[(n, x)] = res
        return res

    # base case
    if (n, x) == (0, 1):
        res = 1
        d[(n, x)] = res
        return res

    if x <= 1 + size[n - 1]:
        res = burger(n - 1, x - 1)
        d[(n, x)] = res
        return res
    else:
        res = p_num[n - 1] + 1 + burger(n - 1, x - 2 - size[n - 1])
        d[(n, x)] = res
        return res


n, x = map(int, input().split())
size, p_num = [1], [1]
for i in range(1, 50 + 1):
    size.append(size[-1] * 2 + 3)
    p_num.append(p_num[-1] * 2 + 1)
d = defaultdict(lambda: -1)

print(burger(n, x))
# print(d)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict


def burger(n, x):
    if d[(n, x)] >= 0:
        return d[(n, x)]

    if x < 1 or x > size[n]:
        d[(n, x)] = 0
        return d[(n, x)]

    # base case
    if (n, x) == (0, 1):
        d[(n, x)] = 1
        return d[(n, x)]

    if x <= 1 + size[n - 1]:
        d[(n, x)] = burger(n - 1, x - 1)
        return d[(n, x)]
    else:
        d[(n, x)] = p_num[n - 1] + 1 + burger(n - 1, x - 2 - size[n - 1])
        return d[(n, x)]


n, x = map(int, input().split())
size, p_num = [1], [1]
for i in range(1, 50 + 1):
    size.append(size[-1] * 2 + 3)
    p_num.append(p_num[-1] * 2 + 1)
d = defaultdict(lambda: -1)

print(burger(n, x))
# print(d)

Submission status: Wrong Answer

Solution code:
N,X = map(int,input().split())
#レベルLに含まれるパティの総数
patty = [None]*(N+1)
patty[0] = 0
for n in range(1,N+1):
    patty[n] = patty[n-1] * 2 + 1

burger = [None]*6
burger[0] = "P"
for i in range(1,5):
    burger[i] = "B"+burger[i-1]+"P"+burger[i-1]+"B"
ans = 0
for x in range(X):
    if burger[i]=="P":ans+=1
print(ans)

Submission status: Wrong Answer

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

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

layer = 1
for _ in range(N):
    layer = layer * 2 + 3


def calc(n, i, layer):
    if n == 1:
        return "BPPPB"[:i].count("P")
    else:
        if i == layer // 2 + 1:
            return cntP[n-1] + 1
        elif i > layer // 2 + 1:
            i = i - layer // 2 - 1
            return cntP[n-1] + calc(n-1, i, (layer-3) // 2)
        elif i < layer // 2 + 1:
            return calc(n-1, i, (layer-3) // 2)

ans = calc(N, X, layer)
print(ans)

Submission status: Wrong Answer

Solution code:
def DEBUG(debug,*args):
    if not debug:
        return
    for i in args:
        print(i)

def dfs(ps, strs, num):
    if ps[num]!=0:
        return (ps[num], strs[num])
    np,ns = dfs(ps, strs, num-1)
    ps[num] =np*2+1
    strs[num]=ns*2+3
    return (ps[num], strs[num])

def dfs2(ps, strs, num, x):
    if num==0:
        return 1
    if x==1:
        return 0
    elif x > 1 and x < 1+strs[num-1]:
        return dfs2(ps, strs, num-1, x-1)
    elif x==1+strs[num-1] or x==2+strs[num-1]:
        return ps[num-1]+1
    elif x> 2+strs[num-1] and x < strs[num]:
        return ps[num-1] + 1 + dfs2(ps, strs, num-1, x-2-strs[num-1])
    elif x==strs[num]:
        return ps[num]
    assert("why?")


if __name__ == "__main__":
    debug=False

    N,X = map(int, input().split())
    ps= [0]*(N+1)
    strs=[0]*(N+1)
    ps[0]=1
    strs[0]=1
    dfs(ps, strs, N) 
    st = dfs2(ps, strs, N, X)
    # DEBUG(debug,st)
    print(st)

Submission status: Wrong Answer

Solution code:
def DEBUG(debug,*args):
    if not debug:
        return
    for i in args:
        print(i)

def dfs(ps, strs, num):
    if ps[num]!=0:
        return (ps[num], strs[num])
    np,ns = dfs(ps, strs, num-1)
    ps[num] =np*2+1
    strs[num]=ns*2+3
    return (ps[num], strs[num])

def dfs2(ps, strs, num, x):
    print("num : {}, x : {}".format(num,x))
    if num==0:
        return 1
    if x==1:
        return 0
    elif x > 1 and x < 1+strs[num-1]:
        return dfs2(ps, strs, num-1, x-1)
    elif x==1+strs[num-1] or x==2+strs[num-1]:
        return ps[num-1]+1
    elif x> 2+strs[num-1] and x < strs[num]:
        return ps[num-1] + 1 + dfs2(ps, strs, num-1, x-2-strs[num-1])
    elif x==strs[num]:
        return ps[num]
    assert("why?")


if __name__ == "__main__":
    debug=False

    N,X = map(int, input().split())
    ps= [0]*(N+1)
    strs=[0]*(N+1)
    ps[0]=1
    strs[0]=1
    dfs(ps, strs, N) 
    st = dfs2(ps, strs, N, X)
    # DEBUG(debug,st)
    print(st)