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:
import sys
sys.setrecursionlimit(10**5)
N, X = map(int, input().split())

layers = [1]
patties = [1]

for i in range(1, N+1):
	layer_i = 2 * layers[i-1] + 3
	patty_i = 2 * patties[i-1] + 1
	layers.append(layer_i)
	patties.append(patty_i)
	
def f(n, x):
	if x == 1:
		return 0
		
	elif 1 < x <= 1 + layers[n-1]:
		return f(n-1, x-1)
		
	elif x == 2 + layers[n-1]:
		return patties[n-1] + 1
		
	elif 2 + layers[n-1] < x <= 2 + 2 * layers[n-1]:
		return patties[n-1] + 1 + f(n-1, x-2-layers[n-1])
		
	else:
		return 2 * patties[n-1] + 1
		
print(f(N, X))

Submission status: Wrong Answer

Solution code:


import sys
sys.setrecursionlimit(10**5)
N, X = map(int, input().split())

layers = [1]
patties = [1]

for i in range(1, N+1):
	layer_i = 2 * layers[i-1] + 3
	patty_i = 2 * patties[i-1] + 1
	layers.append(layer_i)
	patties.append(patty_i)
	
def f(n, x):
	if x == 1:
		return 0
		
	elif 1 < x <= 1 + layers[n-1]:
		return f(n-1, x-1)
		
	elif x == 2 + layers[n-1]:
		return patties[n-1] + 1
		
	elif 2 + layers[n-1] < x <= 2 + 2 * layers[n-1]:
		return patties[n-1] + 1 + f(n-1, x-2-layers[n-1])
	elif x == 3 + 2 * layers[n-1]:
		return 2 * patties[n-1] + 1
		
print(f(N, X))

Submission status: Wrong Answer

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

layers = [1]
patties = [1]

for i in range(N):
	layer_i = 2 * layers[i-1] + 3
	patty_i = 2 * patties[i-1] + 1
	layers.append(layer_i)
	patties.append(patty_i)
	
def f(n, x):
	if x == 1:
		return 0
		
	elif 1 < x <= 1 + layers[n-1]:
		return f(n-1, x-1)
		
	elif x == 2 + layers[n-1]:
		return patties[n-1] + 1
		
	elif 2 + layers[n-1] < x <= 2 + 2 * layers[n-1]:
		return patties[n-1] + 1 + f(n-1, x-2-layers[n-1])
	else:
		return 2 * patties[n-1] + 1
		
print(f(N, X))

Submission status: Wrong Answer

Solution code:
N,X=map(int,input().split())
A=[1]*(N+1)
P=[1]*(N+1)
for i in range(1,N+1):
    P[i]=2*P[i-1]+1
    A[i]=2*P[i]-1

def f(N,X):
    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

print(f(N,X))

Submission status: Wrong Answer

Solution code:
N,X=map(int,input().split())
L=[[1,1] for _ in range(N+1)]
i=0
while i+1<=N:
    L[i+1][0]=L[i][0]*2+1
    L[i+1][1]=L[i+1][0]*2-1
    i+=1

xx=[[1,1,1,1,1]for _ in range(N+1)]
i=1
while i+1<=N:
    xx[i+1][1]=L[i][1]+1
    xx[i+1][2]=L[i][1]+2
    xx[i+1][3]=2*L[i][1]+2
    xx[i+1][4]=2*L[i][1]+3
    i+=1

ans=0
while N>0:
    if xx[N][0]==X:
        break
    elif xx[N][1]>=X:
        N-=1
        X-=1
    elif xx[N][2]==X:
        ans+=1+L[N-1][0]
        break
    elif xx[N][3]>=X:
        ans+=1+L[N-1][0]
        X-=xx[N][2]
        N-=1
    else:
        ans+=1+2*L[N-1][0]
        break

print(ans)

Submission status: Wrong Answer

Solution code:
from functools import lru_cache
N, X = map(int, input().split())
a = [0] * (N)
p = [0] * N
a[0] = 1
p[0] = 1
for i in range(1, N):
    a[i] = a[i-1]*2 + 3
    p[i] = p[i-1]*2 + 1
@lru_cache(maxsize=1000)
def f(n, x):
    if n == 0:
        return 0
    if x == 1:
        return 0
    elif x<=1+a[n-1]:
        return f(n-1, x-1)
    elif x == 2+a[n-1]:
        return p[n-1]+1
    elif 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
print(f(N, X))

Submission status: Wrong Answer

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

    pb = [1]
    p = [1]
    for _ in range(n):
        pb.append(pb[-1] * 2 + 3)
        p.append(p[-1] * 2 + 1)

    ans = 0
    for _ in range(n):
        if x == 0:
            break
        if x >= pb[-2] + 2:
            x -= pb[-2] + 2
            ans += 1 + p[-2]
        else:
            x -= 1
        pb.pop(-1)
        p.pop(-1)

    if x == 1:
        ans += 1

    print(ans)

main()

Submission status: Wrong Answer

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

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

def f(N, X):
    if N == 0:
        return 0 if X == 0 else 1
    if X <= size[N-1] + 1:
        return f(N-1, X-1)
    if X == size[N-1] + 2:
        return f(N-1, X-1) + 1
    if X >= size[N-1] + 3:
        return patty[N-1] + 1 + f(N-1, X-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):
    a.append(a[i]*2+3)
    p.append(p[i]*2+1)

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

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

Submission status: Wrong Answer

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

dp = [1]*(n+1)
res = 0

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

for j in range(n,1,-1):
    if dp[j-1]+2 <= x :
        res += 1 + (dp[j-1]+1)//2
        x -= dp[j-1]+3
    elif dp[j-1]+1 ==x:
        res += (dp[j-1]+1)//2
        x = 0
    else:
        x -=1
    
    if x ==0:
        break
        
if x ==5:
    res += 3
elif x ==0:
    pass
else:
    res +=x-1

print(res)

Submission status: Wrong Answer

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

dp = [1]*(n+1)
res = 0

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

for j in range(n,1,-1):
    if dp[j-1]+2 <= x :
        res += 1 + (dp[j-1]+1)//2
        x -= dp[j-1]+2
    elif dp[j-1]+1 ==x:
        res += (dp[j-1]+1)//2
        x = 0
    else:
        x -=1
    
    if x ==0:
        break
        
if x ==5:
    res += 3
elif x ==0:
    pass
else:
    res +=x-1

print(res)

Submission status: Wrong Answer

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

dp = [1]*(n+1)
res = 0

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

for j in range(n,1,-1):
    if dp[j-1]+2 <= x :
        res += 1 + (dp[j-1]+1)//2
        x -= dp[j-1]+2
    elif dp[j-1]+1 ==x:
        res += (dp[j-1]+1)//2
        x = 0
    else:
        x -=1

if x ==5:
    res += 3

elif x ==0:
    pass

else:
    res +=x-1

print(res)

Submission status: Wrong Answer

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

t = [1]
p = [1]

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

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

print(pathi(n, x))

Submission status: Wrong Answer

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

maisu=[0]*50
pate=[0]*50
maisu[0]=1
pate[0]=1

for i in range(1,50):
    maisu[i]=3+maisu[i-1]*2
    pate[i]=1+pate[i-1]*2

def solve(l,x):
#    print("solve {} {}".format(l,x))
    if l==0:
        return 1
    if x<=1:
        return 0

    if x<1+maisu[l-1]:
        return solve(l-1,x-1)
    if x==2+maisu[l-1]:
        return pate[l-1] + 1

    return pate[l-1] + 1 + solve(l-1,x-2-maisu[l-1])

print(solve(n,x))

Submission status: Wrong Answer

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

t = [1]
p = [1]

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

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

print(pathi(n, x))

Submission status: Wrong Answer

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

t = [1]
p = [1]

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

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

print(pathi(n, x))

Submission status: Wrong Answer

Solution code:
memo1 = {}
def f(i):
    if i==0:
        return 1
    if i in memo1:
        return memo1[i]
    memo1[i] = 2*f(i-1)+3
    return memo1[i]
memo2 = {}
def g(i):
    if i==0:
        return 1
    if i in memo2:
        return memo2[i]
    memo2[i]=2*g(i-1)+1
    return memo2[i]
N,X = map(int,input().split())
cnt = 0
while X>0 and N>0:
    if X>=f(N-1)+2:
        cnt += 1+g(N-1)
        X -= f(N-1)+2
    else:
        X -= 1
    N -= 1
if N==0 and X==1:
    cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
memo1 = {}
def f(i):
    if i==0:
        return 1
    if i in memo1:
        return memo1[i]
    memo1[i] = 2*f(i-1)+3
    return memo1[i]
memo2 = {}
def g(i):
    if i==0:
        return 1
    if i in memo2:
        return memo2[i]
    memo2[i]=2*g(i-1)+1
    return memo2[i]
N,X = map(int,input().split())
cnt = 0
while X>0 and N>0:
    if X>=f(N-1)+2:
        cnt += 1+g(N-1)
        X -= f(N-1)+2
    else:
        X -= 1
    N -= 1
if N==0 and X==2:
    cnt += 1
print(cnt)

Submission status: Wrong Answer

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

p = [0] * -~n
l = [0] * -~n

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

# バーガーの長さは奇数


def rec(m, y):
    if y == 0:
        return 0
    if m == 0:
        return 1 if y == 1 else 0
    h = l[m] // 2  # レベルmの半分より左側の長さ
    if h < y:  # 真ん中含む
        return 1 + p[m - 1] + rec(m - 1, y - h - 1)
    else:
        return rec(m - 1, y - 1)


print(rec(n, x))

Submission status: Wrong Answer

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

p = [0] * -~n
l = [0] * -~n

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

# バーガーの長さは奇数


def rec(m, y):
    if m == 0:
        return 1 if y == 1 else 0
    h = l[m] // 2  # レベルmの半分より左側の長さ
    if h + 1 < y:  # 真ん中含む
        return 1 + p[m - 1] + rec(m - 1, y - h - 1)
    elif h + 1 == y:
        return 1 + p[m - 1]
    else:
        return rec(m - 1, y - 1)


print(rec(n, x))

Submission status: Wrong Answer

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

p = [0] * -~n
l = [0] * -~n

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

# バーガーの長さは奇数


def rec(m, y):
    if m == 0:
        return 1 if y == 1 else 0
    h = l[m] // 2  # レベルmの半分より左側の長さ
    if h < y:  # 真ん中含む
        return 1 + p[m - 1] + rec(m - 1, y - h - 1)
    elif h == y:
        return 1 + p[m - 1]
    else:
        return rec(m - 1, y - 1)


print(rec(n, x))

Submission status: Wrong Answer

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

p = [0] * -~n
l = [0] * -~n

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

# バーガーの長さは奇数


def rec(m, y):
    if y <= 0:
        return 0
    if m == 0 and y > 0:
        return 1

    h = l[m] // 2  # レベルmの半分より左側の長さ
    if h < y:  # 真ん中含む
        return 1 + p[m - 1] + rec(m - 1, y - h - 1)
    elif h == y:
        return 1 + p[m - 1]
    else:
        return rec(m - 1, y - 1)


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

Submission status: Wrong Answer

Solution code:
def examA():
    N = DI()/dec(7)
    ans = N
    print(N)
    return

def examB():
    ans = 0
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    N, X = LI()
    S = [0]*(N+1)
    P = [0]*(N+1)
    S[0] = 1; P[0] = 1
    for i in range(N):
        S[i+1] = S[i]*2 + 3
        P[i+1] = P[i]*2 + 1

    def dfs(n,x):
        if n==0:
            return 0<x
        if x>=S[n-1]+2:
            return 1 + P[n-1] + dfs(n-1,x-2-S[n-1])
        return dfs(n-1,x-1)
    ans = dfs(N,X)
    print(ans)
    return

from decimal import getcontext,Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = dec("0.000000000001")
alphabet = [chr(ord('a') + i) for i in range(26)]
alphabet_convert = {chr(ord('a') + i): i for i in range(26)}

getcontext().prec = 28

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examD()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Submission status: Wrong Answer

Solution code:
N, X = map(int, input().split())
L, C = [1], [1]
for n in range(1,N+1):
    L.append(2*L[-1]+3)
    C.append(2*C[-1]+1)
step = 0
res = 0
for i in reversed(range(N+1)):
    if X<=step+L[i]//2:
        step+=1
    elif X>step+L[i]//2+1:
        step += L[i]//2+1
        res += C[i-1]+1
    else:
        res += C[i-1]+1
        break
print(res)

Submission status: Wrong Answer

Solution code:
def hamb(n,x):
  if x==0 or (x==1 and n!=0):return 0
  elif x==1 and n==0:return 1
  elif x<=s[n-1]+1:return hamb(n-1,x-1)
  elif x==s[n-1]+1:return p[n-1]+1
  else:return hamb(n-1,x-2-s[n-1])+p[n-1]+1
n,x=map(int,input().split())
s=[0]*(n+1)
p=[0]*(n+1)
s[0]=1
p[0]=1
for i in range(n):
  s[i+1]=3+2*s[i]
  p[i+1]=1+2*p[i]
print(hamb(n,x))

Submission status: Wrong Answer

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

def level_n_putty(n):
    if n == 0:
        return 1
    else:
        return 2 * level_n_putty(n-1) + 1

def level_n_hb(n):
    if n == 0:
        return 1
    else:
        return 2 * level_n_hb(n-1) + 3

m = level_n_hb(n)

s = 0
base = 0

while True:
    if x == base + 1:
        if n == 0:
            s += 1
        break
    elif x == base + m:
        break
    else:
        l = level_n_hb(n-1)
        #print(n, base + l + 2, x)
        if x < base + l + 2:
            base += 1
            n -= 1
            m = l
        elif x == base + l + 2:
            s += 1 + level_n_putty(n-1)
            break
        else:
            base = base + l + 2
            s += 1 + level_n_putty(n-1)
            n -= 1
            m = l

print(s)

Submission status: Wrong Answer

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

def level_n_putty(n):
    if n == 0:
        return 1
    else:
        return 2 * level_n_putty(n-1) + 1

def level_n_hb(n):
    if n == 0:
        return 1
    else:
        return 2 * level_n_hb(n-1) + 3

m = level_n_hb(n)

s = 0
base = 0

while True:
    if x == base + 1:
        break
    elif x == base + m:
        break
    else:
        l = level_n_hb(n-1)
        #print(n, base + l + 2, x)
        if x < base + l + 2:
            base += 1
            n -= 1
            m = l
        elif x == base + l + 2:
            s += 1 + level_n_putty(n-1)
            break
        else:
            base = base + l + 2
            s += 1 + level_n_putty(n-1)
            n -= 1
            m = l

print(s)

Submission status: Wrong Answer

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

pate, slice = [1], [1]
for _ in range(n+1):
    pate.append(2 * pate[-1] + 1)
    slice.append(2 * slice[-1] + 3)

ans = 0
while n >= 0 and x > 0:
    if x >= slice[n - 1] + 2:
        ans += pate[n - 1] + 1
        x -= slice[n - 1] + 2
    elif x < slice[n - 1] + 2:
        x -= 1
    n -= 1
print(ans)

Submission status: Wrong Answer

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

sumx=[1]
pathi=[1]
for i in range(n):
  sumx+=[sumx[-1]*2+3]
  pathi+=[pathi[-1]*2+1]
  
if n==0:
  if x==1:
    print(1)
    exit()
    
elif x==1:
  print(0)
  exit()
  

elif x==sumx[-1] or x==sumx[-1]-1:
  print(pathi[-1])
  exit()
  
ans=0

for i in range(n-1,0,-1):
  x-=1
  if x>=sumx[i]:
    ans+=pathi[i]
    x-=sumx[i]
    if x>=1:
      x-=1
      ans+=1


ans+=max(x-1,0)
print(ans)

Submission status: Wrong Answer

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

sumx=[1]
pathi=[1]
for i in range(n):
  sumx+=[sumx[-1]*2+3]
  pathi+=[pathi[-1]*2+1]
  
if n==0:
  if x==1:
    print(1)
    exit()
    
elif x==1:
  print(0)
  exit()
  

elif x==sumx[-1]:
  print(pathi[-1])
  exit()
  
ans=0

for i in range(n-1,0,-1):
  x-=1
  if x>=sumx[i]:
    ans+=pathi[i]
    x-=sumx[i]
    if x>=1:
      x-=1
      ans+=1


ans+=max(x-1,0)
print(ans)

Submission status: Wrong Answer

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

sumx=[1]
pathi=[1]
for i in range(n):
  sumx+=[sumx[-1]*2+3]
  pathi+=[pathi[-1]*2+1]
  
if n==0:
 print(1)
 exit()
    
elif x==1:
  print(0)
  exit()
  
  
ans=0

for i in range(n-1,0,-1):
  x-=1
  if x>=sumx[i]:
    ans+=pathi[i]
    x-=sumx[i]
    if x>=1:
      x-=1
      ans+=1
    if x<=4:
      break

ans+=max(x-1,0)
print(ans)

Submission status: Wrong Answer

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

sumx=[1]
pathi=[1]
for i in range(n):
  sumx+=[sumx[-1]*2+3]
  pathi+=[pathi[-1]*2+1]
  
if n==0:
  if x==1:
    print(1)
    exit()
    
elif x==1:
  print(0)
  exit()
  

elif x==sumx[-1]:
  print(pathi[-1])
  exit()
  
ans=0

for i in range(n-1,0,-1):
  x-=1
  if x>=sumx[i]:
    ans+=pathi[i]
    x-=sumx[i]
    if x>=1:
      x-=1
      ans+=1
    if x<=4:
      break

ans+=max(x-1,0)
print(ans)

Submission status: Wrong Answer

Solution code:
N, X = map(int, input().split())
# a=レベルiバーガーの厚さ, p = レベルiバーガーのパティの数
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):  # レベルNバーガーの下からX層にあるパティの数
    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])
    elif X == 3 + 2 * a[N - 1]:
        return 2 * p[N - 1] + 1

print(f(N, X))

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
l,p=[1],[1]
for i in range(n):
  l+=[l[-1]*2+3]
  p+=[p[-1]*2+1]
x-=1
a=0
while x>0:
  t=l[n]//2
  if x>=t:
    a+=p[n-1]+1
    x-=t
  x-=1
  n-=1
print(a)

Submission status: Wrong Answer

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

def n_pati(l):
  val = 1
  for i in range(l):
    val = val*2+1
  return val

def n_layer(l):
  val = 1
  for i in range(l):
    val = val*2+3
  return val

SUM=0
while 1:
  L = n_layer(N)
  if X >= L//2:
    SUM += n_pati(N-1)
    X -= n_layer(N-1)+1
    if X==0:
      break
    SUM += 1
    X -= 1
    if X==0:
      break
    N -= 1
  else:
    X -= 1
    N -= 1
    
  if N==0:break
  
print(SUM)

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, X = mapint()
burger = [1]*50
pa = [1]*50
for i in range(1, 50):
    burger[i] = burger[i-1]*2+3
    pa[i] = pa[i-1]*2+1

to_eat = X
layer = N
ans = 0
while 1:
    if layer==0:
        ans += to_eat
        break
    if to_eat<=1:
        break
    elif to_eat==burger[layer-1]+2:
        ans += pa[layer-1]+1
        break
    elif to_eat==burger[layer-1]+1:
        ans += pa[layer-1]
        break
    elif to_eat<=burger[layer-1]:
        layer -= 1
        to_eat -= 1
        continue
    else:
        ans += pa[layer-1]+1
        to_eat -= burger[layer-1]+2
        layer -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, X = mapint()
burger = [1]*50
pa = [1]*50
for i in range(1, 50):
    burger[i] = burger[i-1]*2+3
    pa[i] = pa[i-1]*2+1

to_eat = X
layer = N
ans = 0
while 1:
    if to_eat<=1:
        break
    if layer==0:
        ans += to_eat
        break
    elif to_eat==burger[layer-1]+2:
        ans += pa[layer-1]+1
        break
    elif to_eat==burger[layer-1]+1:
        ans += pa[layer-1]
        break
    elif to_eat<=burger[layer-1]:
        layer -= 1
        to_eat -= 1
        continue
    else:
        ans += pa[layer-1]+1
        to_eat -= burger[layer-1]+2
        layer -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, X = mapint()
burger = [1]*50
pa = [1]*50
for i in range(1, 50):
    burger[i] = burger[i-1]*2+3
    pa[i] = pa[i-1]*2+1

to_eat = X
layer = N
ans = 0
while 1:
    if to_eat<=1:
        break
    if layer==0:
        break
    elif to_eat==burger[layer-1]+2:
        ans += pa[layer-1]+1
        break
    elif to_eat==burger[layer-1]+1:
        ans += pa[layer-1]
        break
    elif to_eat<=burger[layer-1]:
        layer -= 1
        to_eat -= 1
        continue
    else:
        ans += pa[layer-1]+1
        to_eat -= burger[layer-1]+2
        layer -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, X = mapint()
burger = [1]*50
pa = [1]*50
for i in range(1, 50):
    burger[i] = burger[i-1]*2+3
    pa[i] = pa[i-1]*2+1

to_eat = X
layer = N
ans = 0
while 1:
    if to_eat<=1:
        break
    elif to_eat==burger[layer-1]+2:
        ans += pa[layer-1]+1
        break
    elif to_eat<=burger[layer-1]+1:
        layer -= 1
        to_eat -= 1
        continue
    else:
        ans += pa[layer-1]+1
        to_eat -= burger[layer-1]+2
        layer -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, X = mapint()
burger = [1]*50
pa = [1]*50
for i in range(1, 50):
    burger[i] = burger[i-1]*2+3
    pa[i] = pa[i-1]*2+1

to_eat = X
layer = N
ans = 0
while 1:
    if to_eat<=1:
        break
    elif to_eat==burger[layer-1]+1:
        ans += pa[layer-1]+1
        break
    elif to_eat<=burger[layer-1]:
        layer -= 1
        to_eat -= 1
        continue
    else:
        ans += pa[layer-1]+1
        to_eat -= burger[layer-1]+2
        layer -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, X = mapint()
burger = [1]*50
pa = [1]*50
for i in range(1, 50):
    burger[i] = burger[i-1]*2+3
    pa[i] = pa[i-1]*2+1

to_eat = X
layer = N
ans = 0
while 1:
    if to_eat<=1:
        break
    elif to_eat==burger[layer-1]+1:
        ans += pa[layer-1]
        break
    elif to_eat<=burger[layer-1]:
        layer -= 1
        to_eat -= 1
        continue
    else:
        ans += pa[layer-1]+1
        to_eat -= burger[layer-1]+2
        layer -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
n,x=map(int, input().split())
p=[1]*(n+1) #パティ
a=[1]*(n+1) #パティとバンズ

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

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

print(f(n,x))

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def main():
    N, X = NMI()
    A = [1]
    P = [1]
    for i in range(N):
        A.append(A[-1]*2+3)
        P.append(P[-1]*2+1)

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

        if x == 1:
            return 0
        elif x <= A[n-1]+1:
            return rec(n-1, x-1)
        elif x == A[n-1]+2:
            return P[n-1]+1
        elif x <= A[n]-1:
            return P[n-1]+1+rec(n-1, x-A[n-1]-2)
        else:
            return P[n]

    print(rec(N, X))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n,x=map(int, input().split())
p=[1]*(n+1) #パティ
a=[1]*(n+1) #パティとバンズ

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

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

print(f(n,x))

Submission status: Wrong Answer

Solution code:
n,x = map(int,input().split())
ans = 0
i = n
while i > 1:
    c = 2**(i+1) - 3
    num_p = 2**i - 1
    
    if 2*c + 3 == x:
        ans += 2*num_p + 1
        break
    elif c + 2 == x:
        ans += num_p + 1
        break
    elif 1 == x:
        break
    
    elif 2 + c <= x:
        x -= 2 + c
        ans += num_p + 1
    else:
        x -= 1
    
    i -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
# 初期入力
import sys
input = sys.stdin.readline
N,X = (int(i) for i in input().split())
DP_all  =[0]*(N+1)
DP_p    =[0]*(N+1)
DP_all[0]   =1
DP_p[0]     =1

#レベル「i+1」バーガーの枚数
for i in range(N):
    DP_all[i+1] =DP_all[i] *2 +3
    DP_p[i+1]   =DP_p[i] *2  +1
#print("総枚数" ,DP_all)
#print("パティ枚数" ,DP_p)

#再帰でパティの枚数を求める L=レベル、x=食べる枚数
def  p_num(L,x):
    if x <=L:
        return 0
    if x ==DP_all[L]:
        return DP_p[L]
    elif x < DP_all[L] //2 +1:
        return p_num(L-1,x -1)
    elif x ==DP_all[L] //2 +1:
        return DP_p[L-1] +1
    elif x > DP_all[L] //2 +1:
        return DP_p[L-1] +1 +p_num(L-1,x -DP_all[L-1] -1)

ans =p_num(N,X)
print(ans)

Submission status: Wrong Answer

Solution code:
n,x=map(int, input().split())
p=[1]*(n+1)
bp=[1]*(n+1)

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

def f(n,x):
    if n==0:
        return 1 if x>=1 else 0
    
    #Lv.nバーガーの真ん中
    center=bp[n]//2
    
    if x==center:
        return p[n-1]+1
    elif x > center:
        return p[n-1]+1+f(n,x-center)
    elif x < center:
        return f(n-1,x-1)

print(f(n,x))

Submission status: Wrong Answer

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

def rec(n, x):
    if x == 0:
        if n == 0:
            return 1
        else:
            return 0
    elif x <= 1 + lbl[n-1]:
        return rec(n-1, x-1)
    else:
        return npl[n-1] + 1 + rec(n-1, x-2-lbl[n-1])

print(rec(n, x))

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
patty=[1]
barger=[1]
ans=0
for i in range(n):
  patty.append(2*patty[-1]+1)
  barger.append(2*barger[-1]+3)
i=n
count=0
mid=True
while x>0:
  count+=1
  for _ in range(n):
    if x>=barger[i]:
      x-=barger[i]
      ans+=patty[i]
      if x>0 and mid:
        ans+=1
        mid=False
      else:
        mid=True
      break
    x-=1
    i-=1
print(ans)

Submission status: Wrong Answer

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

    def chris(a, b):
        if a == 0:
            return 1
        elif b <= a:
            return 0
        hl = l[a]
        if b >= hl - a:
            return nu[a]
        elif hl // 2 + 1 <= b:
            return nu[a - 1] + 1 + chris(a - 1, b - (hl // 2 + 1))
        return chris(a - 1, b - 1)

    print(chris(n, x))


solve()

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, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
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()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N, X = MAP()

L = [0]*(N+1) #レベルiにおける全体の枚数
L[0] = 1

P = [0]*(N+1) #レベルiにおけるパティの枚数
P[0] = 1

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

def solve(i, x):  #レベルiの下からX層におけるパティの枚数
	if i == 0:
		if x == 1:
			return 1
		else:
			return 0

	if x-1 <= L[i-1]:
		return solve(i-1, x-1)
	else:
		return P[i-1] + 1 + solve(i-1, x-L[i-1]-2)

print(solve(N, X))