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())
a = [1]
for _ in range(N - 1):
    a.append(a[-1] * 2 + 3)
p = [1]
for _ in range(N - 1):
    p.append(p[-1] * 2 + 1)
# print(a)
# print(p)
def func(n, x):
    if x == 1:
        return 0
    elif x <= 1 + a[n - 1]:
        return func(n - 1, x - 1)
    elif x == 2 + a[n - 1]:
        return p[n - 1] + 1
    elif x <= 2 + a[n - 1] * 2:
        return p[n - 1] + 1 + func(n - 1, x - a[n - 1] - 2)
    else:
        return p[n - 1] * 2
print(func(N, X))

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
ln = [0] * (n+1)
p = [0] * (n+1)
ln[0] = 1
p[0] = 1
for i in range(1,n+1):
    ln[i] = ln[i-1] * 2 + 3
    p[i] = p[i-1] * 2 + 1
# print(ln)
# print(p)
ans = 0
def Xmas(n,x):
    global ans
    if n == 0 or x == ln[n] or x == 0 or x == (ln[n]+1) // 2:
        if n == 0:
            return ans
        elif x == 0:
            return ans
        elif x == ln[n]:
            return ans + p[n-1] + 1
        elif x == ((ln[n]+1) // 2):
            return ans + p[n-1] + 1
    else:
        if x < ((ln[n] +1)// 2):
            return Xmas(n-1,x-1)
        else:
            ans += (p[n-1] + 1)
            return Xmas(n-1,x-(ln[n-1] + 2))
print(Xmas(n,x))

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
ln = [0] * (n+1)
p = [0] * (n+1)
ln[0] = 1
p[0] = 1
for i in range(1,n+1):
    ln[i] = ln[i-1] * 2 + 3
    p[i] = p[i-1] * 2 + 1
# print(ln)
# print(p)
ans = 0
def Xmas(n,x):
    global ans
    if n == 0 or x == ln[n] or x == 0 or x == (ln[n]+1) // 2:
        if n == 0:
            return ans
        elif x == 0:
            return ans
        elif x == ln[n]:
            return ans + p[n-1] + 1
        elif x == ((ln[n]+1) // 2):
            return ans + p[n-1] + 1
    else:
        if x < ((ln[n] +1)// 2):
            return Xmas(n-1,x-1)
        else:
            ans += (p[n]+1) // 2
            return Xmas(n-1,x-(ln[n-1] + 2))
print(Xmas(n,x))

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
ln = [0] * (n+1)
p = [0] * (n+1)
ln[0] = 1
p[0] = 1
for i in range(1,n+1):
    ln[i] = ln[i-1] * 2 + 3
    p[i] = p[i-1] * 2 + 1
# print(ln)
# print(p)
ans = 0
def Xmas(n,x):
    global ans
    if n == 0 or x == ln[n] or x == 0 or x == (ln[n]+1) // 2:
        if n == 0:
            return ans
        elif x == 0:
            return ans
        elif x == ln[n]:
            return ans + p[n-1]
        elif x == ((ln[n]+1) // 2):
            return ans + p[n-1] + 1
    else:
        if x < ((ln[n] +1)// 2):
            return Xmas(n-1,x-1)
        else:
            ans += (p[n]+1) // 2
            return Xmas(n-1,x-(ln[n-1] + 2))
print(Xmas(n,x))

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
ln = [0] * (n+1)
p = [0] * (n+1)
ln[0] = 1
p[0] = 1
for i in range(1,n+1):
    ln[i] = ln[i-1] * 2 + 3
    p[i] = p[i-1] * 2 + 1
# print(ln)
# print(p)
ans = 0
def Xmas(n,x):
    global ans
    if n == 0 or x == ln[n] or x == 0 or x == (ln[n]+1) // 2:
        if n == 0:
            return ans
        elif x == 0:
            return ans
        elif x == ln[n]:
            return ans + p[n] + 1
        elif x == ((ln[n]+1) // 2):
            return ans + p[n-1] + 1
    else:
        if x < ((ln[n] +1)// 2):
            return Xmas(n-1,x-1)
        else:
            ans += (p[n]+1) // 2
            return Xmas(n-1,x-(ln[n-1] + 2))
print(Xmas(n,x))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, X = lr()
burger = [0] * 51 # 1-indexed
burger[0] = 1
patty = [0] * 51
patty[0] = 1
for i in range(1, N+1):
    burger[i] = 2 * burger[i-1] + 3
    patty[i] = 2 * patty[i-1] + 1

#print(burger)
answer = 0
while X:
    if X <= 1:
        break
    elif X == burger[N]:
        answer += patty[N]
        break
    if X > burger[N] // 2:
        answer += patty[N-1] + 1  # +1は中央部
        X -= burger[N-1] + 2
        N -= 1
        continue
    else:
        X -= 1
        N -= 1

print(answer)

Submission status: Wrong Answer

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

def dfs(level,z):
    if level==0:
        return 0 if z<=0 else 1
    elif z==(2+atsusa[level-1]):
        return 1+pati_kazu[level-1]
    elif z==(3+atsusa[level-1]*2):
        return pati_kazu[level-1]*2+1
    elif 1<z<=(1+atsusa[level-1]):
        return dfs(level-1,z-1)
    else:
        return 1+pati_kazu[level-1]+dfs(level-1,z-2-atsusa[level-1])

print(dfs(n,x))

Submission status: Wrong Answer

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

def dfs(level,z):
    if z<=1 or level<=0:
        return 0
    elif z==(2+atsusa[level-1]):
        return 1+pati_kazu[level-1]
    elif z==(3+atsusa[level-1]*2):
        return pati_kazu[level-1]*2+1
    elif 1<z<=(1+atsusa[level-1]):
        return dfs(level-1,z-1)
    else:
        return 1+pati_kazu[level-1]+dfs(level-1,z-2-atsusa[level-1])

print(dfs(n,x))

Submission status: Wrong Answer

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

def dfs(level,z):
    if z<=1:
        return 0
    elif 1<z<=atsusa[level-1]:
        return dfs(level-1,z-1)
    elif z<=(2+atsusa[level-1]):
        return 1+pati_kazu[level-1]
    else:
        return 1+pati_kazu[level-1]+dfs(level-1,z-2-atsusa[level-1])

print(dfs(n,x))

Submission status: Wrong Answer

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

tmp_p = 1
tmp_v = 1
p_li = [1]
v_li = [1]
b0_li = [0,1,2,3,3]

for i in range(n):
    tmp_p = tmp_p * 2 + 1
    tmp_v = tmp_v * 2 + 3
    p_li.append(tmp_p)
    v_li.append(tmp_v)

def dfs(x,sou,num):
    if x == v_li[sou]:
        print(num+p_li[sou])
        return
    elif x == 1:
        print(num)
        return
    elif x <= v_li[sou-1]+1:
        if sou == 1:
            print(num+b0_li[x-2])
            return
        else:
            dfs(x-1,sou-1,num)
    elif x == v_li[sou-1] + 2:
        print(num+p_li[sou-1]+1)
        return
    elif x <= 2*v_li[sou-1]+2:
        dfs(x-2-v_li[sou-1],sou-1,num+p_li[sou-1]+1)

dfs(x,n,0)

Submission status: Wrong Answer

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

tmp_p = 1
tmp_v = 1
p_li = [1]
v_li = [1]
b0_li = [0,1,2,3,3]

for i in range(n):
    tmp_p = tmp_p * 2 + 1
    tmp_v = tmp_v * 2 + 3
    p_li.append(tmp_p)
    v_li.append(tmp_v)

def dfs(x,sou,num):
    if x == v_li[sou]:
        print(p_li[sou])
        return
    elif x == 1:
        print(num)
        return
    elif x <= v_li[sou-1]+1:
        if sou == 1:
            print(num+b0_li[x-2])
            return
        else:
            dfs(x-1,sou-1,num)
    elif x == v_li[sou-1] + 2:
        print(num+p_li[sou-1]+1)
        return
    elif x <= 2*v_li[sou-1]+2:
        dfs(x-2-v_li[sou-1],sou-1,num+p_li[sou-1]+1)

dfs(x,n,0)

Submission status: Wrong Answer

Solution code:
from functools import reduce
n_,x_=map(int,input().split())
a=[1]
p=[1]
for i in range(n_):
    a.append(2*a[-1]+3)
    p.append(2*p[-1]+1)

def f(n,x):
    if n==0:
        return 0
    elif 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:
from functools import reduce
n_,x_=map(int,input().split())
a=[1]
p=[1]
for i in range(n_):
    a.append(2*a[-1]+3)
    p.append(2*p[-1]+1)

def f(n,x):
    global a,p
    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:
from functools import reduce
n_,x_=map(int,input().split())
a=[1]
p=[1]
for i in range(n_):
    a.append(2*a[-1]+3)
    p.append(2*p[-1]+1)

def f(n,x):
    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:
N, X = map(int, input().split())
burger  = [1] * (N+1)
patty = [1] * (N+1)
for i in range(1, N+1):
    burger[i] = burger[i-1] * 2 + 3
    patty[i] = patty[i-1] * 2 + 1


def func(level, x):
    if level == 0:
        return 0 if x <= 0 else 1
    if burger[level] + 1 < x:
        return func(level-1, x-burger[level]-2) + patty[level] + 1
    else:
        return func(level-1, x-1)


print(func(N, X))

Submission status: Wrong Answer

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


def func(level, x):
    if level == 0:
        return 0 if x <= 0 else 1
    if burger[level] + 1 <= x:
        return func(level-1, x-burger[level]-2) + patty[level] + 1
    else:
        return func(level-1, x-1)


print(func(N, X))

Submission status: Wrong Answer

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


def func(level, x):
    if level == -1:
        return 0 if x <= 0 else 1
    if burger[level] + 1 <= x:
        return func(level-1, x-burger[level]-2) + patty[level] + 1
    else:
        return func(level-1, x-1)


print(func(N, X))

Submission status: Wrong Answer

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


def func(level, x):
    if level == 0:
        return 0
    if burger[level] + 1 <= x:
        return func(level-1, x-burger[level]-2) + patty[level] + 1
    else:
        return func(level-1, x-1)


print(func(N, X))

Submission status: Wrong Answer

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


def func(level, x):
    if level == 0 or x == 1:
        return 0
    if burger[level-1] + 1 <= x:
        return func(level-1, x-burger[level-1]-2) + patty[level-1] + 1
    else:
        return func(level-1, x-1)


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

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
B=[1] #レベルiバーガーの厚さ
P=[1] #レベルiバーガーのパティの数
for i in range(n-1):
    B.append(B[-1]*2+3)
    P.append(P[-1]*2+1)
ans=0
for i in range(n):
    if x==1:
        break
    elif 1<x<B[n-i-1]+2:
        x-=1
    elif x==B[n-i-1]+2:
        ans+=P[n-i-1]+1
        break
    elif x>B[n-i-1]+2:
        ans+=P[n-i-1]+1
        x-=B[n-i-1]+2
    else:
        ans+=2*P[n-i-1]+1
        break
print(ans)

Submission status: Wrong Answer

Solution code:
N,X=map(int,input().split())
P=[1]
A=[1]
for i in range(N):
  P.append(1+2*P[i])
  A.append(3+2*A[i])
def f(n,x):
  if n==0:
    return 0
  else:
    if x==1:
      return 0
    if 1<x<2+A[n-1]:
      return f(n-1,x-1)
    if x==2+A[n-1]:
      return 1+P[n-1]
    if 2+A[n-1]<x<3+2*A[n-1]:
      return 1+P[n-1]+f(n-1,x-(2+A[n-1]))
    if x==3+2*A[n-1]:
      return 1+2*P[n-1]
print(f(N,X))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,X=map(int,input().split())
B=[0]
P=[1]
A=[1]
for i in range(N):
  B.append(2+2*B[i])
  P.append(1+2*P[i])
  A.append((2+2*B[i])+(1+2*P[i]))
def f(n,x):
  if n==0:
    return 0
  elif x==1:
    return 0
  elif 1<x<2+A[n-1]:
    return f(n-1,x-1)
  elif x==2+A[n-1]:
    return 1+P[n-1]
  elif 2+A[n-1]<x<A[n]:
    return 1+P[n-1]+f(n-1,x-(2+A[n-1]))
  elif x==A[n]:
    return 1+2*P[n-1]
print(f(N,X))

Submission status: Wrong Answer

Solution code:
N,X=map(int,input().split())
B=[0]
P=[1]
A=[1]
for i in range(N):
  B.append(2+2*B[i])
  P.append(1+2*P[i])
  A.append((2+2*B[i])+(1+2*P[i]))
def f(n,x):
  if n==0:
    return 0
  elif x==0 or x==1:
    return 0
  elif 1<x<2+A[n-1]:
    return f(n-1,x-1)
  elif x==2+A[n-1]:
    return 1+P[n-1]
  elif 2+A[n-1]<x<A[n]:
    return 1+P[n-1]+f(n-1,x-(2+A[n-1]))
  elif x==A[n]:
    return 1+2*P[n-1]
print(f(N,X))

Submission status: Wrong Answer

Solution code:
def main():

    burgur = [0] * 51
    burgur[0] = 1
    pate = [0] * 51
    pate[0] = 1
    for i in range(50):
        burgur[i+1] = burgur[i] * 2 + 3
        pate[i+1] = pate[i] * 2 + 1
    
    N, X = map(int, input().split())

    X -= 1
    ans = 0
    for i in reversed(range(1, N+1)):
        if X >= burgur[i-1] + 1:
            ans += pate[i-1] + 1
            X -= (burgur[i-1] + 2)
        else: 
            X -= 1
    if X == 0:
        ans += 1
    print(ans)
    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

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


def solve(n, x):
    #print(n, x)
    if n == 0:
        return(1)
    if x == L[n]:
        return(P[n])
    elif x <= n:
        return(0)
    else:
        ret = 0
        if x >= L[n-1] + 1:
            ret += P[n-1]
            if x > L[n-1] + 1:
                ret += solve(n-1, x - (L[n-1] + 2)) + 1
        else:
            ret = solve(n-1, x-1)
        return(ret)


print(solve(N, X))

Submission status: Wrong Answer

Solution code:
def main():
    from functools import lru_cache
    import sys

    sys.setrecursionlimit(10 ** 7)

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

    size = [0] * (N + 1)
    patty = [0] * (N + 1)
    size[0] = 1
    patty[0] = 1
    for lv in range(1, N + 1):
        size[lv] = size[lv - 1] * 2 + 3
        patty[lv] = patty[lv - 1] * 2 + 1

    @lru_cache(maxsize=None)
    def burger(lv, x):
        if lv == 0:
            return x > 0

        if x <= 1:
            return 0

        if x <= 1 + size[lv - 1]:
            return burger(lv - 1, x - 1)

        if x == 1 + size[lv - 1] + 1:
            return patty[lv - 1] + 1

        if x <= 1 + size[lv - 1] + 1 + size[lv - 1]:
            return patty[lv - 1] + 1 + burger(lv - 1, x - (1 + size[lv - 1] + 1))

        return patty[lv]

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,x = map(int,input().split())
fi = x-1
aa = [1]
bb = [1]
a = 1
b = 1
for i in range(50):
    a = a*2 + 3
    b = b*2 + 1
    aa.append(a)
    bb.append(b)
    
def bu(lv , x):
    if n == 0:
        return 1
    
    l = aa[lv-1]
    num = bb[lv-1]
    
    if x == 1:
        return 0
    elif x <= l+1:
        return bu(lv-1,x-1)
    elif x == l+2:
        return num + 1
    elif x <= (l+1)*2:
        return num + 1 + bu(lv-1,x-l-2)
    else:
        return num*2 + 1
    
print(bu(n,x))

Submission status: Wrong Answer

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

a,p = [1], [1] #総枚数a,パティの枚数がp
for i in range(N): #a[i] = iバーガーの枚数
    a.append(a[i] *2 +3)
    p.append(p[i] *2 +1)

def f(N,X):
    if N == 0:
        return 0 if N<= 0 else 1
    elif X <= 1 + a[N-1]:#真ん中以下の場合
        return f(N-1,X-1)#N-1バーガーでX-1（バンズがふえているので）枚食べるのと同じ
    else:
        return p[N-1] +1 + f(N-1, X-2-a[N-1])#N-1バーガー+真ん中パティ+N-1バーガーのうち[X-2-N-1バーガーの枚数]分だけ食べる
print(f(N,X))

Submission status: Wrong Answer

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

# a : レベルlでの長さ
# p : レベルlでのP数
a,p = [1], [1]
for i in range(n):
    a.append(2*a[-1]+3)
    p.append(2*p[-1]+1)

# f(l,x) : レベルlでの下からxまでのP数
def f(l, x):
    if l==0:
        if x==1:
            return 1
        else:
            return 0
    
    elif x<=a[l-1]+1:
        return f(l-1, x-1)

    else:
        return p[l-1] + 1 + f(l-1, x-a[l-1]-2)

print(f(n,x))

Submission status: Wrong Answer

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

# a : レベルlでの長さ
# p : レベルlでのP数
a,p = [1], [1]
for i in range(n):
    a.append(2*a[-1]+3)
    p.append(2*p[-1]+1)

# f(l,x) : レベルlでの下からxまでのP数
def f(l, x):
    if l==0:
        if x==1:
            return 1
        else:
            return 0
    
    elif x<=a[l-1]+1:
        return f(l-1, x)

    else:
        return p[l-1] + 1 + f(l-1, x-a[l-1]-2)

print(f(n,x))

Submission status: Wrong Answer

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

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

ans = 0
i = n
while x > 0:
    mid = (b[i] + 1) // 2
    if x < mid:
        i -= 1
        x -= 1
    elif x == mid:
        ans += p[i - 1] + 1
        break
    else:
        ans += p[i - 1] + 1
        i -= 1
        x -= mid

print(ans)

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,x = LI()
    l = [4*2**i-3 for i in range(n+1)]
    s = [2*2**i-1 for i in range(n+1)]
    ans = 0
    while n:
        if x == 1:
            break
        elif x <= l[n-1]+1:
            n -= 1
            x -= 1
        elif x < l[n]:
            ans += 1+s[n-1]
            x -= 2+l[n-1]
            n -= 1
        else:
            ans += s[n]
            break
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
def layers(n):
    result = 1
    for _ in range(0, n):
        result = result * 2 + 3
    return result


def meat(n):
    result = 1
    for _ in range(0, n):
        result = result * 2 + 1
    return result


def calc(n, x):
    before_layer = layers(n - 1)
    before_meat = meat(n - 1)
    if x == 1:
        return 0
    elif x <= 1 + before_layer:
        return calc(n - 1, x - 1)
    elif x == 2 + before_layer:
        return 1 + before_meat
    elif x <= 2 + 2 * before_layer:
        return 1 + before_meat + calc(n - 1, x - 2 - before_layer)
    elif x == 3 + 2 * before_layer:
        return 2 * before_meat + 1


def main():
    n, x = map(int, input().split())
    print(calc(n, x))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math
import fractions
from collections import deque
from collections import defaultdict
sys.setrecursionlimit(10**7)

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

g = [1] * 51
p = [1] * 51

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


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

    if x <= g[n - 1] + 1:
        return rec(n - 1, x - 1)
    elif x == g[n - 1] + 2:
        return p[n - 1] + 1
    else:
        return rec(n - 1, x - g[n - 1] - 2) + p[n - 1] + 1


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

Submission status: Wrong Answer

Solution code:
N,X=map(int,input().split(' '))
l = 1
p = 1
L=[]
P=[]
for i in range(N):
    l = 2*l+3
    p = 2*p+1
    L.append(l)
    P.append(p)
def pans(l,x):
    if l==1:
        return list('BPPPB'[:x]).count(P)

    elif x<=L[l-2]+1:
        return pans(l-1,x)
    elif X==L[l-2]+2:
        return P[l-2]+1
    else:
        return P[l-2]+1+pans(l-1,x-(2+L[l-2]))
print(pans(N,X))

Submission status: Wrong Answer

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

tmp = 1
pat = 1
plist = [1]
bag_list = [1]
for i in range(n):
    tmp = 1 + tmp + 1 + tmp + 1
    pat = pat * 2 + 1
    bag_list.append(tmp)
    plist.append(pat)

def calc(x, nn):
    if x == 1:
        return 1 if nn == 0 else 0
    tt = bag_list[nn-1] + 2
    if x == tt:
        return plist[nn-1] + 1
    elif x < tt:
        return calc(x-1, nn-1)
    elif x > tt:
        return calc(x-1-1-bag_list[nn-1], nn-1) + plist[nn-1] + 1
    elif x == bag_list[nn]:
        return plist[nn]

print(calc(x, n))

Submission status: Wrong Answer

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

tmp = 1
pat = 1
plist = [1]
bag_list = [1]
for i in range(n):
    tmp = 1 + tmp + 1 + tmp + 1
    pat = pat * 2 + 1
    bag_list.append(tmp)
    plist.append(pat)

def calc(x, nn):
    if x == 1:
        return 0
    tt = bag_list[nn-1] + 2
    if x == tt:
        return plist[nn-1] + 1
    elif x < tt:
        return calc(x-1, nn-1)
    elif x > tt:
        return calc(x-1 - bag_list[nn-1]-1, nn-1) + plist[nn-1] + 1
    elif x == bag_list[nn]:
        return plist[nn]

if tmp == bag_list[n-1]:
    print(plist[n-1])
else:
    print(calc(x, n))

Submission status: Wrong Answer

Solution code:
def solve(level, eat_layer, all_layers, meat):
    if eat_layer == 1:
        return 0
    elif eat_layer <= all_layers[level - 1] + 1:
        return solve(level - 1, eat_layer - 1, all_layers, meat)
    elif eat_layer == all_layers[level - 1] + 2:
        return 1 + meat[level - 1]
    elif eat_layer <= 2 + 2 * all_layers[level - 1]:
        return 1 + meat[level - 1] + solve(level - 1, eat_layer - 2 - all_layers[level - 1], all_layers, meat)
    elif eat_layer == 3 + 2 * all_layers[level - 1]:
        return 2 * meat[level - 1] + 1


def main():
    level, eat_layer = map(int, input().split())
    level_layer = [1]
    meat = [1]
    for _ in range(level):
        level_layer.append(2 * level_layer[-1] + 3)
        meat.append(2 * meat[-1] + 1)
    print(solve(level, eat_layer, level_layer, meat))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def solve(L, x):
    if L == 1:
        return 1
    elif x == 1:
        return 0
    elif (2**(L+2)-3)//2 >= x >= 2:
        return solve(L-1, x-1)
    elif x == (2**(L+2)-3)//2 +1:
        return (2**(L+1)-1)//2+1
    elif (2**(L+2)-3)//2+2 <= x <= (2**(L+2)-3)-1:
        return 2**(L+1)-1-solve(L-1,(2**(L+2)-3)-1-x)
    elif x==(2**(L+2)-3):
        return 2**(L+1)-1

N, X = map(int, input().split())
print(solve(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(a[i] * 2 + 1)

def f(N, X):
    if N == 0:
        return 0 if X <= 0 else 1
    elif X <= 1 + a[N-1]:
        # B(N-1) | P(N-1)B の真ん中のパティの前までの範囲がわかればいい場合
        # Xから先頭のバンの数を引いて、N-1の先頭からX-1までの数を数えるために再帰で呼び出す
        return f(N-1,X-1)
    else:
        # 真ん中のパティ以上の枚数を数える必要がある場合
        # 一つ前のレベルのパティの数 + 真ん中のパティ + f(レベル-1, この関数呼び出しで知りたいトータルの枚数-2(先頭のバンと真ん中のパティ)-一つ前のレベルのハンバーガーのトータルの枚数)
        # X-2-a[N-1] → X - (B(N-1)P)|ここから後ろの先頭からK枚を数えるために再帰で呼び出す
        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())

def burger(N,X):
  print(N,X)
  if N == 0 and X == 1:
    return 1
  if X == 0:
    return 0
  twopow = pow(2,N)
  if X == 4*twopow-3:
    return 2*twopow-1
  if X > 2*twopow-2:
    return twopow + burger(N-1,X-2*twopow+1)
  elif X <= 2*twopow-2:
    return burger(N-1,X-1)

print(burger(N,X))

Submission status: Wrong Answer

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

A, P = [1], [1]
for i in range(50):
    A.append(A[i] * 2 + 3)
    P.append(P[i] * 2 + 1)

    
def f(level, x):
    if x == 1:
        return 0
    else:
        if 1 < x <= 1 + A[level-1]:
            return f(level-1, x-1)
        else:
            if x == 2 + A[level-1]:
                return 1 + P[level-1]
            elif 2+A[level-1] < x <= 2 + 2*A[level-1]:
                return 1 + P[level-1]+f(level-1, x-2-A[level-1])
            elif x == 3 + 2*A[level-1]:
                return 1 + 2*P[level-1]


print(f(n, x))

Submission status: Wrong Answer

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


def p(level):
    if level == 0:
        return 1
    return 2*p(level-1)+1


def a(level):
    if level == 0:
        return 1
    return 2*a(level-1)+3


def f(level, x):
    if x == 1:
        return 0
    else:
        if 1 < x <= 1 + a(level-1):
            return f(level-1, x-1)
        else:
            if x == 2 + a(level-1):
                return 1 + p(level-1)
            elif 2+a(level-1) < x <= 2 + 2*a(level-1):
                return 1 + p(level-1)+f(level-1, x-2-a(level-1))
            elif x == 3 + 2*a(level-1):
                return 1 + 2*p(level-1)


print(f(n, x))

Submission status: Wrong Answer

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


def p(level):
    if level == 0:
        return 1
    return 2*p(level-1)+1


def a(level):
    if level == 0:
        return 1
    return 2*a(level-1)+3


def f(level, x):
    if x == 1:
        return 0
    else:
        ai_1 = a(level-1)
        pi_1 = p(level-1)
        if 1 < x <= 1 + ai_1:
            return f(level-1, x-1)
        else:
            if x == 2 + ai_1:
                return 1 + pi_1
            elif 2+ai_1 < x <= 2 + 2*ai_1:
                return 1 + pi_1+f(level-1, x-2-ai_1)
            elif x == 3 + 2*ai_1:
                return 1 + 2*pi_1


print(f(n, x))

Submission status: Wrong Answer

Solution code:
N, X = (int(i) for i in input().split())  
L = [1]
P = [1]

for _ in range(N):
  L.append(L[-1] * 2 + 3)
  P.append(P[-1] * 2 + 1)

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

#print(L,P)
print(count(X, N))

Submission status: Wrong Answer

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


def p(level):
    if level == 0:
        return 1
    return 2*p(level-1)+1


def a(level):
    if level == 0:
        return 1
    return 2*a(level-1)+3


def f(level, x):
    if x <= 1:
        return 0
    else:
        ai_1 = a(level-1)
        if 1 < x <= 1 + ai_1:
            return f(level-1, x-1)
        else:
            pi_1 = p(level-1)
            if x == 2 + ai_1:
                return 1 + pi_1
            elif 2+ai_1 < x <= 2 + 2*ai_1:
                return 1 + pi_1+f(level-1, x-2-ai_1)
            elif x == 3 + 2*ai_1:
                return 1 + 2*pi_1


print(f(n, x))

Submission status: Wrong Answer

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


def p(level):
    if level == 0:
        return 1
    return 2*p(level-1)+1


def a(level):
    if level == 0:
        return 1
    return 2*a(level-1)+3


def f(level, x):
    if x == 1:
        return 0
    else:
        ai_1 = a(level-1)
        if 1 < x <= 1 + ai_1:
            return f(level-1, x-1)
        else:
            pi_1 = p(level-1)
            if x == 2 + ai_1:
                return 1 + pi_1
            elif 2+ai_1 < x <= 2 + 2*ai_1:
                return 1 + pi_1+f(level-1, x-2-ai_1)
            elif x == 3 + 2*ai_1:
                return 1 + 2*pi_1


print(f(n, x))

Submission status: Wrong Answer

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

position = 2**(n+2)-3
result = 0
while x > 0:
    position = (position-1)//2
    if x == position*2+3:
        result += position + 1
        x = 0
    elif x == position+2:
        result += position//2 + 1
        x = 0
    elif x > position:
        x -= position
        result += position//2+1
    x -= 1
    position -= 1
print(result)

Submission status: Wrong Answer

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

position = 2**(n+2)-3
print(position)
result = 0
while x > 0:
    position = (position-1)//2
    if x > position:
        x -= position
        result += position//2+1
    x -= 1
    position -= 1
print(result)

Submission status: Wrong Answer

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

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