Problem: 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?

Submission attempts (in order):
import math



#     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
    elif X <= 1 + size[N - 1]:
        return f(N - 1, X - 1)
    elif X == 2 + size[N - 1]:
        return patty[N - 1] + 1
    elif X <= 2 + 2 * size[N - 1]:
        return patty[N - 1] + 1 + f(N - 1, X - 2 - size[N - 1])
    elif X == 3 + 2 * size[N - 1]:
        return 2 * patty[N - 1] + 1


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


size, patty = [1], [1]
for i in range(N+1):
    size.append(size[i] * 2 + 3)
    patty.append(patty[i] * 2 + 1)
for i in range(N):
    print(size)
for i in range(N):
    print(patty)
print(f(N, X))


import math



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


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


import math



#     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 - 1]:
        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)


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


import math



#     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:
        # print(1)
        return 0 if not N == 0 else 1
    elif X <= 1 + size[N - 1]:
        # print(2)
        return f(N - 1, X - 1)
    elif X == 2 + size[N - 1]:
        # print(3)
        return patty[N - 1] + 1
    elif X <= 2 + 2 * size[N - 1]:
        # print(4)
        return patty[N - 1] + 1 + f(N - 1, X - 2 - size[N - 1])
    elif X == 3 + 2 * size[N - 1]:
        # print(5)
        return 2 * patty[N - 1] + 1


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


size, patty = [1], [1]
for i in range(N):
    size.append(size[i] * 2 + 3)
    patty.append(patty[i] * 2 + 1)

#     print(size)


print(f(N, X))


Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Accepted