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):
N, X = map(int, input().split())


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:  
        return 0

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

     + レベルL-1バーガー + 真ん中のパティ
    elif x == 2 + thick[n - 1]:
        return patti[n - 1] + 1

     + レベルL-1バーガー + 真ん中のパティ + レベルL-1バーガーの途中まで
    elif 2 + thick[n - 1] < x <= 2 * thick[n - 1] + 2:
        return patti[n - 1] + 1 + solve(n - 1, x - 1 - thick[n - 1] - 1)

     + レベルL-1バーガー + 真ん中のパティ + レベルL-1バーガー + 最後のバン
    elif x == 2 * thick[n - 1] + 3:
        return 2 * patti[n - 1] + 1


print(solve(N, X))


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


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:  
        return 0

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

     + レベルL-1バーガー + 真ん中のパティ
    elif x == 2 + thick[n - 1]:
        return patti[n - 1] + 1

     + レベルL-1バーガー + 真ん中のパティ + レベルL-1バーガーの途中まで
    elif 2 + thick[n - 1] < x < 2 * thick[n - 1] + 3:
        return patti[n - 1] + 1 + solve(n - 1, x - 1 - thick[n - 1] - 1)

     + レベルL-1バーガー + 真ん中のパティ + レベルL-1バーガー + 最後のバン
    else:
        return 2 * patti[n - 1] + 1


print(solve(N, X))


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


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


ans = 0


def solve(n, x):
    global ans
    if x == 1:  
        return

     + レベルL-1バーガーの途中まで
    elif 1 < x < 1 + thick[n - 1]:
        solve(n - 1, x - 1)

     + レベルL-1バーガー + 真ん中のパティ
    elif x == 2 + thick[n - 1]:
        ans += patti[n - 1] + 1
        return

     + レベルL-1バーガー + 真ん中のパティ + レベルL-1バーガーの途中まで
    elif 2 + thick[n - 1] < x < 2 * thick[n - 1] + 3:
        ans += patti[n - 1] + 1
        solve(n - 1, x - 1 - thick[n - 1] - 1)

     + レベルL-1バーガー + 真ん中のパティ + レベルL-1バーガー + 最後のバン
    else:
        ans += 2 * patti[n - 1] + 1
        return


solve(N, X)
print(ans)


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


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:  
        return 0

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

     + レベルL-1バーガー + 真ん中のパティ
    elif x == 2 + thick[n - 1]:
        return patti[n - 1] + 1

     + レベルL-1バーガー + 真ん中のパティ + レベルL-1バーガーの途中まで
    elif 2 + thick[n - 1] < x < 2 * thick[n - 1] + 3:
        return patti[n - 1] + 1 + solve(n - 1, x - 1 - thick[n - 1] - 1)

     + レベルL-1バーガー + 真ん中のパティ + レベルL-1バーガー + 最後のバン
    else:
        return 2 * patti[n - 1] + 1


print(solve(N, X))


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


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:  
        return 0 + (n == 0)

    
    elif 1 < x <= 1 + thick[n - 1]:
        return solve(n - 1, x - 1)

    
    else:
        return patti[n - 1] + 1 + solve(n - 1, x - 1 - thick[n - 1] - 1)


print(solve(N, X))


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

burger_size = [1]
patty_num = [1]
for i in range(50):
    burger_size.append(2 * burger_size[-1] + 3)
    patty_num.append(2 * patty_num[-1] + 1)



def dfs(n, x):
    if burger_size[n] == x:
        return patty_num[n]

    if x == 1:
        return 0

    elif 1 < x <= 1 + burger_size[n - 1]:
        return dfs(n - 1, x - 1)

    elif x == 1 + burger_size[n - 1] + 1:
        return patty_num[n - 1] + 1

    elif 1 + burger_size[n - 1] + 1 < x < burger_size[n]:
        return patty_num[n - 1] + 1 + dfs(n - 1, x - burger_size[n - 1] - 2)


print(dfs(N, X))


Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Runtime Error

Accepted