Buggy python submission (verdict: Runtime Error):
# D - Christmas

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

height = [1] # レベルnバーガーの高さ
for _ in range(N):
    height.append(height[-1]*2 + 3)

# dp[i][j]はレベルiバーガーの下j層に含まれるパティの数。ただしレベルiバーガーの高さの範囲外には-1を格納
dp = [[0]+[-1]*height[-1] for _ in range(N+1)] 
dp[0][1] = 1
    
for level in range(1,N+1):
    for n_from_bottom in range(1,height[-1]+1):
        if n_from_bottom > height[level]:
            break
        elif n_from_bottom == 2 * height[level-1] + 3:
            dp[level][n_from_bottom] = dp[level-1][height[level-1]] * 2 + 1
        elif n_from_bottom > height[level-1] + 2: 
            dp[level][n_from_bottom] = dp[level-1][height[level-1]] + 1 + dp[level-1][n_from_bottom - (height[level-1] + 2)]
        elif n_from_bottom == height[level-1] + 2: # 前のバーガー+底のバン+パティ
            dp[level][n_from_bottom] = dp[level-1][height[level-1]] + 1
        else:
            dp[level][n_from_bottom] = dp[level-1][n_from_bottom-1]
    
print(dp[N][X])

Fixed submission:
# D - Christmas

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

height = [1] # レベルiバーガーの高さ
for _ in range(N):
    height.append(height[-1]*2 + 3)
    
patty = [1] # レベルiバーガーに含まれるパティの総数
for _ in range(N):
    patty.append(patty[-1]*2 + 1)

def dp(n,x): # レベルnバーガーの下からx個の層に含まれるパティの数
    if n == 0:
        return 1
    elif x == 1:
        return 0
    elif x <= 1 + height[n-1]:
        return dp(n-1, x-1)
    elif x == 2 + height[n-1]:
        return patty[n-1] + 1
    elif 2 + height[n-1] < x <= height[n] - 1:
        return patty[n-1] + 1 + dp(n-1, x - (height[n-1] + 2))
    else:
        return patty[n]
    
print(dp(N,X))

Buggy python submission (verdict: Runtime Error):
# D - Christmas

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

height = [1] # レベルnバーガーの高さ
for _ in range(N):
    height.append(height[-1]*2 + 3)

# dp[i][j]はレベルiバーガーの下j層に含まれるパティの数。ただしレベルiバーガーの高さの範囲外には-1を格納
dp = [[0]+[-1]*height[-1] for _ in range(N+1)] 
dp[0][1] = 1
    
for level in range(1,N+1):
    for n_from_bottom in range(1,height[-1]+1):
        if n_from_bottom > height[level]:
            break
        elif n_from_bottom == 2 * height[level-1] + 3:
            dp[level][n_from_bottom] = dp[level-1][height[level-1]] * 2 + 1
        elif n_from_bottom > height[level-1] + 2: 
            dp[level][n_from_bottom] = dp[level-1][height[level-1]] + 1 + dp[level-1][n_from_bottom - (height[level-1] + 2)]
        elif n_from_bottom == height[level-1] + 2: # 前のバーガー+底のバン+パティ
            dp[level][n_from_bottom] = dp[level-1][height[level-1]] + 1
        else:
            dp[level][n_from_bottom] = dp[level-1][n_from_bottom-1]
    
print(dp[N][X])

Fixed submission:
# D - Christmas

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

height = [1] # レベルiバーガーの高さ
for _ in range(N):
    height.append(height[-1]*2 + 3)
    
patty = [1] # レベルiバーガーに含まれるパティの総数
for _ in range(N):
    patty.append(patty[-1]*2 + 1)

def dp(n,x): # レベルnバーガーの下からx個の層に含まれるパティの数
    if n == 0:
        return 1
    elif x == 1:
        return 0
    elif x <= 1 + height[n-1]:
        return dp(n-1, x-1)
    elif x == 2 + height[n-1]:
        return patty[n-1] + 1
    elif 2 + height[n-1] < x <= height[n] - 1:
        return patty[n-1] + 1 + dp(n-1, x - (height[n-1] + 2))
    else:
        return patty[n]
    
print(dp(N,X))