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

count_p = [1] * (N+1) # パティの数
for i in range(1, N+1):
    count_p[i] += count_p[i-1] * 2

length = [1] * (N+1) # バーガーの長さ
for i in range(1, N+1) :
    length[i] += (length[i-1] + 1) * 2

def F(n, x): # レベルnバーガーの下x層のあるパティの数
    if n == 0:
        return x
    if x == length[n] // 2 + 1:
        return count_p[n-1] + 1
    elif x > length[n] // 2 + 1:
        return count_p[n-1] + 1 + F(n-1, x-(length[n]//2+1))
    else:
        return F(n-1, max(0, x-1))
print(F(N, X))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    n,x = MAP()
    L = [1]*n
    P = [1]*n

    for  i in range(1,n):
        L[i] = 2* L[i-1] +3
        P[i] = 2* P[i-1] + 1

    def func(N, X):
        if N==0:
            return 0 if X <= 0 else 1

        elif X< L[N-1] + 1:
            return func(N-1, X-1)

        else:
            return P[N-1] + 1 + func(N-1, X-L[N-1] -2)

    print(func(n,x))

if  __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    n,x = MAP()
    L = [1]*n
    P = [1]*n

    for  i in range(1,n):
        L[i] = 2* L[i-1] +3
        P[i] = 2* P[i-1] + 1

    def func(N, X):
        if N==0:
            if X == 1:
                return 1
            else:
                return 0

        elif X< L[N-1] + 1:
            return func(N-1, X-1)

        else:
            return P[N-1] + 1 + func(N-1, X-L[N-1] -2)

    print(func(n,x))

if  __name__=='__main__':
    main()

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:

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

def solve(n, x, a, p):
    if x == 1:
        return 0
    elif 1 < x and x <= 1 + a[n - 1]:
        return solve(n - 1,x - 1, a, p)
    elif x == 2 + a[n - 1]:
        return p[n - 1] + 1
    elif 2 + a[n - 1] < x and x <= 2 * a[i - 1] + 2:
        return p[n - 1] + 1 + solve(n - 1, x - 2 - a[i - 1],a,p)
    else:
        return 2 * p[n - 1] + 1
n, x = list(map(int, input().split()))
print(solve(n,x,a,p))

Submission status: Wrong Answer

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

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

print(burger(n,x))

Submission status: Wrong Answer

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

def burger(n,x):
    if n ==0:
        return 1
    elif x == 1:
        return 0
    elif x > 1 and x<=1+s[n-1]:
        return burger(n-1,x-1)
    elif x == 2+s[n-1]:
        return p[n-1] + 1
    elif x > 2+s[n-1] and x <= 2 + s[n-1] * 2:
        return p[n-1] + 1 + burger(n-1,x-s[n-1]-2)
    elif x <= 3 + s[n-1] * 2:
        return 2 + s[n-1] * 2
    else:
        print("ERROR")

print(burger(n,x))

Submission status: Wrong Answer

Solution code:
from sys import stdin

N, X = [int(x) for x in stdin.readline().rstrip().split()]
burger = [(1, 1)]
level = 0

while level < N:
    burger.append((burger[-1][0] * 2 + 3, burger[-1][1] * 2 + 1))
    level += 1

ans = 0
while N > 0 and X > N:
    if X < burger[N - 1][0]:
        N -= 1
        X -= 1
    if X == burger[N - 1][0]:
        ans += 1
        X -= 2
        N -= 1
    if burger[N - 1][0] < X:
        X -= burger[N - 1][0] + 2
        ans += burger[N - 1][1] + 1
        N -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**5)

def solve(n, x):
  if n == 0:
    if x > 1:
      return 1
    else:
      return 0
  else:
    ans = 0
    burger_prev = 2**(n+1)-3
    pate_prev = 2**n-1
    if x > 1:
      if x < burger_prev+1:
        ans += solve(n-1 ,x-1)
      else:
        ans += pate_prev
        if x > burger_prev+1:
          ans += 1
          if x > burger_prev*2+2:
            ans += pate_prev
          else:
            ans += solve(n-1, x-2-burger_prev)
    return ans

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

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**5)

def solve(n, x):
  if n == 0:
    if x > 1:
      return 1
    else:
      return 0
  else:
    ans = 0
    burger_prev = 2**(n+1)-3
    pate_prev = 2**n-1
    if x > 1:
      if x < burger_prev+1:
        ans += solve(n-1 ,x-1)
      else:
        ans += pate_prev
        if x > burger_prev+2:
          ans += 1
          if x > burger_prev*2+2:
            ans += pate_prev
          else:
            ans += solve(n-1, x-2-burger_prev)
    return ans

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

Submission status: Wrong Answer

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

ans=0
while n and k:
	if k>burg[n][0]//2:
		ans += burg[n-1][1]+1
		k -= burg[n-1][0]+2
	else:k -= 1
	n -= 1
print(ans)

Submission status: Wrong Answer

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

T = [1]*(N + 1)
P = [1]*(N + 1)
for i in range(1, N+1):
	P[i] = P[i-1]*2 + 1
	T[i] = T[i-1]*2 + 3
def pate(n, x):
	if n == 0:
		if x > 0: return 1
		return 0
	mid = T[n]//2
	if x < mid:
		return pate(n-1, x-1)
	elif mid == x:
		return 1 + pate(n-1, x-2)
	else:
		return P[n-1] + 1 + pate(n-1, x-mid-1)

print(pate(N, X))

Submission status: Wrong Answer

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

T = [1]*(N + 1)
P = [1]*(N + 1)
for i in range(1, N+1):
	P[i] = P[i-1]*2 + 1
	T[i] = T[i-1]*2 + 3
print(T)
def pate(n, x):
	if n == 0:
		if x > 0: return 1
		return 0
	mid = T[n]//2
	if x < mid:
		print(n, x, mid, "a")
		return pate(n-1, x-1)
	elif mid == x:
		print(n, x, mid, "b")
		return 1 + pate(n-1, x-2)
	else:
		print(n, x, mid, "c")
		return P[n-1] + 1 + pate(n-1, x-mid-1)

print(pate(N, X))

Submission status: Wrong Answer

Solution code:
#%%
N, X = map(int, input().split())
point = []
ans = 0

a = 1
p = 1
for i in range(N):
    a *= 2
    a += 3
    p *= 2
    p += 1

while a != 1:
    if X == a :
        ans += p
        break
    elif (a+1)//2+1 <= X <= a-1:
        X -= 2+(a-3)//2
        ans += p//2 + 1
    elif  X == (a+1)//2:
        ans += p//2 + 1
        break
    elif 2 <= X <= (a+1)//2-1:
        X -= 1
    elif X == 1:
        break
    
    a -= 3
    a //= 2
    p -= 1
    p //= 2

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict, deque
from heapq import *
sys.setrecursionlimit(200000)
input = sys.stdin.readline

N, M, = map(int, input().split())
# N = int(input())
# L = [int(v) for v in input().split()]
# L = [[int(v) for v in input().split()] for _ in range(N)]
# L = [int(input()) for _ in range(N)]
# L = [list(input().strip())  for _ in range(N)]
# S = input().strip()

m = {}
def f(n):
    if m.get(n) != None:
        return m[n]
    if n == 0:
        m[n] = (1, 1)
    else:
        b = f(n - 1)
        m[n] = (b[0] * 2 + 3, b[1] * 2 + 1)
    return m[n]

f(N)

def ff(n, t):
    if n == 0:
        return 1 if t == 1 else 0
    elif t <= 1 + m[n - 1][0]:
        return ff(n - 1, t - 1)
    else:
        return m[n - 1][1] + 1 + ff(n - 1, t - 2 - m[n - 1][0])

print(ff(N, M))

Submission status: Wrong Answer

Solution code:
n,x = map(int,input().split())
dp_a=[1]
dp_p=[1]
for i in range(1,n):
  dp_a.append(2*dp_a[i-1] + 3)
  dp_p.append(2*dp_p[i-1] + 1)  
  
def burger(n,x):
  if n==0:
    if x==1:      
      return 1
    else:
      return 0
    
  if x < dp_a[n-1]+1:
    return burger(n-1, x-1)
  else:
    return dp_p[n-1] +1 +burger(n-1, x-dp_a[n-1]-2)  

print(burger(n,x))

Submission status: Wrong Answer

Solution code:
n,x = map(int,input().split())
dp_a=[1]
dp_p=[1]
for i in range(1,n):
  dp_a.append(2*dp_a[i-1] + 3)
  dp_p.append(2*dp_p[i-1] + 1)  
  
def burger(n,x):
  if n==0:
    if x==1:      
      return 1
    else:
      return 0
    
  if x < dp_a[n-1]+1:
    return burger(n-1, x-1)
  else:
    return dp_p[n-1] +1 +burger(n-1, x-dp_a[n-1]-2)  

burger(n,x)

Submission status: Wrong Answer

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

a = [1] #i番目にはi番目に作られるハンバーガーの大きさが入っている : a[i+1] = 2 * a[i] + 3
p = [1] #i番目にはi番目に作られるハンバーガーのパティの枚数　: p[i+1] = 2 * p[i] + 1
for i in range(N):
    a.append(2*a[i]+3)
    p.append(2*p[i]+1)
def function(N,X):
    if N <= 0 :
        return 0 if X<= 0 else 1
    elif 1 < X  and X <= a[N-1] + 1 :
        ret = function(N-1,X-1)
        return ret
    else:
        ret  = 1 + p[N-1]
        ret +=  function(N-1,X-a[N-1]-2)
        return ret
print(function(N,X))

Submission status: Wrong Answer

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

a = [1] #i番目にはi番目に作られるハンバーガーの大きさが入っている : a[i+1] = 2 * a[i] + 3
p = [1] #i番目にはi番目に作られるハンバーガーのパティの枚数　: p[i+1] = 2 * p[i] + 1
for i in range(N):
    a.append(2*a[i]+3)
    p.append(2*p[i]+1)
def function(N,X):
    if N == 0 :
        return 1
    else:
        if X <= 0 :
            return 0
        elif 1 < X  and X <= a[N-1] + 2 :
            ret = function(N-1,X-1)
            return ret
        else:
            ret  = 1 + p[N-1]
            ret +=  function(N-1,X-a[N-1]-2)
            return ret
print(function(N,X))

Submission status: Wrong Answer

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

a = [1] #i番目にはi番目に作られるハンバーガーの大きさが入っている : a[i+1] = 2 * a[i] + 3
p = [1] #i番目にはi番目に作られるハンバーガーのパティの枚数　: p[i+1] = 2 * p[i] + 1
for i in range(N):
    a.append(2*a[i]+3)
    p.append(2*p[i]+1)
def function(N,X):
    if N == 0 :
        return 1
    else:
        if X <= 0 :
            return 0
        elif 1 < X  and X < a[N-1] + 2 :
            ret = function(N-1,X-1)
            return ret
        elif X == (a[N-1] + 2):
            return 1 + a[N-1]
        else:
            ret  = 1 + p[N-1]
            ret +=  function(N-1,X-a[N-1]-2)
            return ret
print(function(N,X))

Submission status: Wrong Answer

Solution code:
N, X = map(int, input().split())
h = [1]
p = [1]
for i in range(N):
    h.append(h[i]*2+3)
    p.append(p[i]*2+1)
def f(N,X):
    if X == 1:
        return 0
    elif 1 < X and X <= 1 + h[N-1]:
        return f(N-1,X-1)
    elif X == 2 + h[N-1]:
        return p[N-1] + 1
    elif 2 + h[N-1] < X and X <= 2 + 2 * h[N-1]:
        return p[N-1] + 1 + f(N-1,X-2-h[N-1])
    elif X == 3 + 2 * h[N-1]:
        return p[N]
print(f(N,X))

Submission status: Wrong Answer

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

dp = ['' for i in range(51)]
p = [1]
h = [1]

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


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

    if x <= 1 + h[n - 1]:
        return rec(n - 1, x - 1)

    if x == 2 + h[n - 1]:
        return p[n - 1] + 1

    if x <= 2 + h[n - 1] * 2:
        return p[n - 1] + 1 + rec(n - 1, x - 2 - h[n - 1])

    return p[n]


print(rec(n, x))

Submission status: Wrong Answer

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

dp = ['' for i in range(51)]
p = [1]
h = [1]

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


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

    if x <= 1 + h[n - 1]:
        return rec(n - 1, x - 1)

    if x == 2 + h[n - 1]:
        return p[n - 1] + 1

    if x <= 2 + h[n - 1] * 2:
        return p[n - 1] + 1 + rec(n - 1, x - 2 - h[n - 1])

    return p[n - 1] * 2 + 1
    # r = 0

    # t = min(x, 1)
    # r += 0
    # x -= t

    # t = min(x, h[n - 1])
    # r += rec(n - 1, t)
    # x -= t

    # t = min(x, 1)
    # r += t
    # x -= t

    # t = min(x, h[n - 1])
    # r += rec(n - 1, t)
    # x -= t

    # return r

print(rec(n, x))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
n, x = map(int, input().split())
a, p = [1], [1]
for i in range(n):
    a.append(2*a[i]+3)
    p.append(2*p[i]+1)


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

print(f(n,x))

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
L = [1] * n
P_num = [1] * n

for i in range(n-1):
  L[i + 1] = L[i] * 2 + 3
  P_num[i + 1] = P_num[i] * 2 + 1

def pati_num(n, x):
  if n == 0:
    if x > 1:
      return 1
    else:
      return 0
  elif x <= 1 + L[n-1]:
    return pati_num(n-1, x-1)
  else:
    return P_num[n-1] + 1 + pati_num(n-1, x-2-L[n-1])
print(pati_num(n, x))

Submission status: Wrong Answer

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

N,X=map(int,input().split())
b,p = [1 for _ in range(N+1)],[1 for _ in range(N+1)]

for i in range(1,N+1):
    b[i] = b[i-1]*2+3
    p[i] = p[i-1]*2+1
print(b)
print(f(N,X))

Submission status: Wrong Answer

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

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


def count(x, n):
    if n == 0:
        return max(0, x)
    if x >= (total_counts[n] + 1) // 2:
        return p_counts[n - 1] + 1 + count(x - total_counts[n - 1] - 2, n - 1)
    else:
        return count(x - 1, n - 1)


print(count(x, n))

Submission status: Wrong Answer

Solution code:
N, X = [int(i) for i in input().split()]
p = [1]
l = 1
for i in range(N):
    p.append(p[-1] * 2 + 1)
    l = 2 * l + 3
ban_l = 1
ban_r = l
pate = l//2+1
cnt = 0
for i in range(N+1):
    if X == pate:
        if pate == ban_l:
            cnt += 1
            break
        else:
            cnt += p[N-(i+1)] + 1
            break
    elif X == ban_l:
        break
    elif X < pate:
        ban_l = ban_l + 1
        ban_r = pate - 1
        pate = (pate+ban_l)//2
    elif X < ban_r:
        cnt += p[N-(i+1)] + 1
        ban_l = pate + 1
        pate = (pate+ban_r)//2
        ban_r = ban_r - 1
    else:
        cnt += p[N-i] + 1
        break
print(cnt)

Submission status: Wrong Answer

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 calc(n,x):
    if n==0:
        if x <= 0:
            return 0
        else:
            return 1
    elif x < 1 + a[n-1]:
        return calc(n-1,x-1)
    else:
        return p[n-1] + 1 + calc(n-1,x-2-a[n-1])

print(calc(N,X))

Submission status: Wrong Answer

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

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

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

print(solve(n,x))

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] * 2 + 3)
    p.append(p[i] * 2 + 1)


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


print(f(N, X))

Submission status: Wrong Answer

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

pos = X
eat = 0
for i in range(N-1, -1, -1):
    nlayer = 2 ** (i+2) - 3
    npatie = 2 ** (i+1) - 1
    if pos == 1:
        break
    elif pos <= 1 + nlayer:
        pos -= 1
        continue
    elif pos == 2 + nlayer:
        eat += npatie + 1
        break
    elif pos <= nlayer * 2 + 2:
        eat += npatie + 1
        pos -= nlayer + 2
    else:
        eat += npatie * 2 + 1
        break

print(eat)

Submission status: Wrong Answer

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

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

def f(lv, x):
    c = a[lv-1] + 2
    if x == 1:
        # print(f"1, {lv}, {x}")
        return 0
    elif 1 < x < c:
        # print(f"2, {lv}, {x}")
        return f(lv-1, x-1)
    elif x == c:
        # print(f"3, {lv}, {x}")
        return p[lv-1] + 1
    elif c < x < a[lv]:
        # print(f"4, {lv}, {x}")
        return p[lv-1] + 1 + f(lv-1, x-c)
    else:
        # print(f"5, {lv}, {x}")
        return p[lv]

print(f(N, X))

Submission status: Wrong Answer

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

def burger(n):
  if n == 0:
    return 'P'
  else:
    s = burger(n-1)
    return 'B' + s + 'P' + s + 'B'
  
def layer(n):
  return 2**(n+2)-3 # 層の数

def layhalf(n):
  return 2**(n+1)-2 # 中央のパテよりも下（上）にある層数

def pate(n):
  return 2**(n+1)-1 # パテの数

def search(n, x):
  global ans
  
  if x <= 0:
    pass
  elif layer(n) - n <= x:
    ans += pate(n)
  elif layhalf(n) + 1 <= x:
    ans += pate(n - 1) + 1
    search(n - 1, x - layhalf(n) - 2)
  elif layhalf(n) == x:
    ans += pate(n - 1)
  else:
    search(n - 1, x - 1)
    
search(n, x)
print(ans)

Submission status: Wrong Answer

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

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

p = [0]*(n+1)
p[0] = 1
for i in range(1,n+1):
  p[i] = p[i-1]*2+1
  
ans = 0  
def bts(a,b):
  global ans
  if b == 1:
    ans += 0
  elif 1 < b < l[a-1]+1:
    bts(a-1,b-1)
  elif b == l[a-1]+1:
    ans += p[a-1]
  elif b == l[a-1]+2:
    ans += p[a-1]+1
  elif l[a-1]+2 < b < l[a-1]*2+2:
    ans += p[a-1]+1
    bts(a-1,b-2-l[a-1])
  else:
    ans += p[a-1]+2

bts(n,x)
  
print(ans)

Submission status: Wrong Answer

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

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

p = [0]*(n+1)
p[0] = 1
for i in range(1,n+1):
  p[i] = p[i-1]*2+1
  
ans = 0  
def bts(a,b):
  global ans
  if b <= a:
    ans += 0
  elif a < b < l[a-1]+1:
    bts(a-1,b-1)
  elif  b == l[a-1]+1:
    ans += p[a-1]
  elif b == l[a-1]+2:
    ans += p[a-1]+1
  elif l[a-1]+2 < b < l[a-1]*2+2:
    ans += p[a-1]+1
    bts(a-1,b-2-l[a-1])
  else:
    ans += p[a-1]+2

bts(n,x)
  
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, x = na()
bg = "P"
an = 2 ** (n+2) - 3
bn = 2 ** (n+1) - 1
if an > x:
    print(bn)
else:
    for i in range(n):
        bg = "B" + bg + "P" + bg + "B"
        if len(bg) > x:
            bg = bg[:x]
    print(bg[:x].count("P"))

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
a=[1]
p=[1]
for i in range(n-1):
    a.append(a[i]*2+3)
    p.append(p[i]*2+1)
def f(n,x):
  if n==0 and x==1:
    return 1
  elif n==0 or x<=1:
    return 0
  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:
n,x=map(int,input().split())
a=[1]
p=[1]
for i in range(n-1):
    a.append(a[i]*2+3)
    p.append(p[i]*2+1)
def f(n,x):
  if n==0 and x==1:
    return 1
  elif n==0:
    return 0
  elif x<=1:
    return 0
  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:
n,x=map(int,input().split())
a=[1]
p=[1]
for i in range(n-1):
    a.append(a[i]*2+3)
    p.append(p[i]*2+1)
def f(n,x):
  if n==0 and x==1:
    return 1
  elif n==0:
    return 0
  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:
n,x=map(int,input().split())
a=[1]
p=[1]
for i in range(n-1):
    a.append(a[i]*2+3)
    p.append(p[i]*2+1)
def f(n,x):
  if n==0 or x<=1:
    return 0
  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:
n,x=map(int,input().split())
plist=[1]
blist=[1]
for i in range(n):
  plist.append(plist[-1]*2+1)
  blist.append(blist[-1]*2+3)
def patty(n,x):
  if n==0:
    return 0
  else:
    if x==1:
      return 0
    elif 1<x and x<=blist[n-1]+1:
      return patty(n-1,x-1)
    elif x==blist[n-1]+2:
      return plist[n-1]+1
    elif 2+blist[n-1]<x and 2*blist[n-1]+2>=x:
      return plist[n-1]+patty(n-1,x-2-blist[n-1])+1
    else:
      return plist[n]
print(patty(n,x))

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
plist=[1]
blist=[1]
for i in range(n):
  plist.append(plist[-1]*2+1)
  blist.append(blist[-1]*2+3)
def patty(n,x):
  if x==1:
    return 0
  elif n==0:
    return 0
  else:
    if 1<x and x<=blist[n-1]+1:
      return patty(n-1,x-1)
    elif x==blist[n-1]+2:
      return plist[n-1]+1
    elif 2+blist[n-1]<x and 2*blist[n-1]+2>=x:
      return plist[n-1]+patty(n-1,x-2-blist[n-1])+1
    else:
      return plist[n]
print(patty(n,x))

Submission status: Wrong Answer

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

print(f(n,x))

Submission status: Wrong Answer

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

def dp(a, b):
    if a == 1:
        if 1 <= b <= 4:
            return b-1
        else:
            return 3
    elif b == 1:
        return 0
    elif 1 < b < 2**(a+1)-1:
        return dp(a-1, b-1)
    elif b == 2**(a+1)-1:
        return dp(a-1, 2**(a+1)-3) + 1
    elif 2**(a+1)-1 < b < a:
        return dp(a-1, 2**(a+1)-3) + 1 + dp(a-1, b+1-2**(a+1))
    elif b == 2**(a+2)-3:
        return dp(a-1, 2**(a+1)-3) * 2 + 1
    
print(dp(n, x))

Submission status: Wrong Answer

Solution code:

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

nlen = [0] * (N+1)
nlen[0] = 1

for i in range(N):
    i += 1

    nlen[i] = 3 + nlen[i-1] * 2

    
    
num = [0] * (N+1)

p = 0
b = 0

amari = X


for i in range(N):

    i = N-i

    num[i-1] += 2 * num[i]
    p += num[i]
    b += num[i] * 2

    if 3 + 2 * nlen[i-1]  == amari :

        num[i-1] += 2

        p += 1
        b += 2

        amari = 0

    elif 2 + 2 * nlen[i-1] == amari:

        num[i-1] += 2

        p += 1
        b += 1

    elif 2 + nlen[i-1] <= amari:

        num[i-1] += 1

        p += 1
        b += 1

        amari -= 2 + nlen[i-1]

    elif 1 + nlen[i-1] == amari:

        num[i-1] += 1

        b += 1

        amari = 0

    elif 1 <= amari:

        b += 1
        amari -= 1

print (p + num[0])

Submission status: Wrong Answer

Solution code:

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

nlen = [0] * (N+1)
nlen[0] = 1

for i in range(N):
    i += 1

    nlen[i] = 3 + nlen[i-1] * 2

    
    
num = [0] * (N+1)

p = 0
b = 0

amari = X


for i in range(N):

    i = N-i

    num[i-1] += 2 * num[i]
    p += num[i]
    b += num[i] * 2

    if 3 + 2 * nlen[i-1]  == amari :

        num[i-1] += 2

        p += 1
        b += 2

        amari = 0

    elif 2 + nlen[i-1] <= amari:

        num[i-1] += 1

        p += 1
        b += 1

        amari -= 2 + nlen[i-1]

    elif 1 + nlen[i-1] == amari:

        num[i-1] += 1

        b += 1

        amari = 0

    elif 1 <= amari:

        b += 1
        amari -= 1

print (p + num[0])

Submission status: Wrong Answer

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):
    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: Wrong Answer

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

n_all = [1] + [0] * N
n_p = [1] + [0] * N
for i in range(1, N + 1):
    n_all[i] = n_all[i - 1] * 2 + 3
    n_p[i] = n_p[i - 1] * 2 + 1
    
def f(l, x):
    if l == 0:
        return 1
    if x <= 1:
        return 0
    elif x < n_all[l - 1] + 1:
        return f(l - 1, x - 1)
    elif x == n_all[l - 1] + 1:
        return n_p[l - 1]
    elif x < n_all[l - 1] * 2 + 2:
        return n_p[l - 1] + 1 + f(l - 1, x - n_all[l - 1] - 2)
    else:
        return n_p[l - 1] * 2 + 1
      
print(f(N, X))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(1000000)

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

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


def L(i, X):
    if i == 0:
        if X == 0:
            return 0
        else:
            return 1
    else:
        if X <= 1:
            return 0
        elif 1 < X < l[i-1]:
            return L(i-1, X-1)
        elif X == l[i-1]:
            return p[i-1]+1
        elif l[i-1] < X < l[i]:
            return p[i-1]+1+L(i-1, X-l[i-1]-2)
        else:
            return p[i]


print(L(N, X))

Submission status: Wrong Answer

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

memo = [{} for _ in range(51)]

def rec(x, k):
    """レベルxバーガーを下からk枚食べた時のパティの枚数"""
    M = 2 ** (x+2) - 3
    if k in memo[x].keys():
        return memo[x][k]
    if x == 0:
        return 1
    else:
        if k <= (M-1) // 2:
            ret = rec(x-1, k-1)
            memo[x][k] = ret
        elif k >= (M+1) // 2:
            ret = rec(x-1, 2**(x+1)-3) + 1 + rec(x-1, k - (M-(M+1)//2+1))
            memo[x][k] = ret
        else:
            ret = rec(x-1, 2**(x+1)-3) + 1
            memo[x][k] = ret
        return ret

def solve(N: int, X: int):
    print(rec(N, X)-1)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    solve(N, X)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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):
  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:
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 X == 1 or N == 0:
    return 0
  elif N == 1:
    return 0
  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))