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


Patti = [1]  # レベルLバーガーに含まれているパティの数
Size = [1]   # レベルLバーガーの大きさ
for i in range(50):
    Patti.append(Patti[-1] * 2 + 1)
    Size.append(Size[-1] * 2 + 3)


def solve(n, x):
    # 一番下のバンのみ
    if x == 1:
        return 0

    # 一番下のバン + レベルL-1バーガーのどこかまで
    if 1 < x <= 1 + Size[n - 1]:
        return solve(n - 1, x - 1)

    # 一番下のバン + レベルL-1バーガー + 真ん中のパティまで
    if x == 1 + Size[n - 1] + 1:
        return Patti[n - 1] + 1

    # 一番下のバン + レベルL-1バーガー + 真ん中のパティ + レベルL-1バーガーの途中まで
    if 1 + Size[n - 1] + 1 < x < Size[n]:
        return 1 + Patti[n - 1] + solve(n - 1, x - (1 + Size[n - 1] + 1))

    # レベルLバーガーすべて
    if x == Size[n]:
        return Patti[n]


print(solve(N, X))

Submission status: Wrong Answer

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

hambs = [(1, 1)]
for l in range(1, n+1):
    n_p, n_l = hambs[l-1]
    hambs.append((2*n_p+1, 2*n_l+3))
# for h in hambs:
#     print(h)

def eat(m, y):
    if y == 0:
        return 0
    if m == 0:
        return 1

    if y < 2+hambs[m-1][1]:
        return eat(m-1, y-1)
    elif y == 2+hambs[n-1][1]:
        return hambs[m-1][0] + 1
    elif 2+hambs[m-1][1] < y and y < hambs[m][1]:
        return hambs[m-1][0] + 1 + eat(m-1, y-(2+hambs[m-1][1]))
    else:
        return hambs[m][0]
    
print(eat(n, x))

Submission status: Wrong Answer

Solution code:
import math


# def burger_generator(n):
#     if n == 0:
#         return int("101", 2)
#     else:
#         lt = burger_generator(n-1)
#         x1 = 1 + (lt << 1)
#         length = int(math.log2(x1)) + 1
#         x1 = x1 + (lt << length + 1)
#         length = int(math.log2(x1)) + 1
#         return x1 + (1 << length)


def f(N, X):
    if X == 1:
        return 0
    elif X <= 1 + size[N - 1]:
        return f(N - 1, X - 1)
    elif X == 2 + size[N - 1]:
        return patty[N - 1] + 1
    elif X <= 2 + 2 * size[N - 1]:
        return patty[N - 1] + 1 + f(N - 1, X - 2 - size[N - 1])
    elif X == 3 + 2 * size[N - 1]:
        return 2 * patty[N - 1] + 1


N, X = map(int, input().split())
# burger = format(burger_generator(N), "b")
# print(burger[-K:].count("0"))
size, patty = [1], [1]
for i in range(N+1):
    size.append(size[i] * 2 + 3)
    patty.append(patty[i] * 2 + 1)
# for i in range(N):
#     print(size)
# for i in range(N):
#     print(patty)
print(f(N, X))

Submission status: Wrong Answer

Solution code:
import math


# def burger_generator(n):
#     if n == 0:
#         return int("101", 2)
#     else:
#         lt = burger_generator(n-1)
#         x1 = 1 + (lt << 1)
#         length = int(math.log2(x1)) + 1
#         x1 = x1 + (lt << length + 1)
#         length = int(math.log2(x1)) + 1
#         return x1 + (1 << length)


def f(N, X):
    if X == 1:
        return 0
    elif X <= 1 + size[N - 1]:
        return f(N - 1, X - 1)
    elif X == 2 + size[N - 1]:
        return patty[N - 1] + 1
    elif X <= 2 + 2 * size[N - 1]:
        return patty[N - 1] + 1 + f(N - 1, X - 2 - size[N - 1])
    elif X == 3 + 2 * size[N - 1]:
        return 2 * patty[N - 1] + 1


N, X = map(int, input().split())
# burger = format(burger_generator(N), "b")
# print(burger[-K:].count("0"))
size, patty = [1], [1]
for i in range(N+1):
    size.append(size[i] * 2 + 3)
    patty.append(patty[i] * 2 + 1)
for i in range(N):
    print(size)
for i in range(N):
    print(patty)
print(f(N, X))

Submission status: Wrong Answer

Solution code:
import math


# def burger_generator(n):
#     if n == 0:
#         return int("101", 2)
#     else:
#         lt = burger_generator(n-1)
#         x1 = 1 + (lt << 1)
#         length = int(math.log2(x1)) + 1
#         x1 = x1 + (lt << length + 1)
#         length = int(math.log2(x1)) + 1
#         return x1 + (1 << length)


def f(N, X):
    if X == 1:
        return 0
    elif X <= 1 + size[N - 1]:
        return f(N - 1, X - 1)
    elif X == 2 + size[N - 1]:
        return patty[N - 1] + 1
    elif X <= 2 + 2 * size[N - 1]:
        return patty[N - 1] + 1 + f(N - 1, X - 2 - size[N - 1])
    elif X == 3 + 2 * size[N - 1]:
        return 2 * patty[N - 1] + 1


N, X = map(int, input().split())
# burger = format(burger_generator(N), "b")
# print(burger[-K:].count("0"))
size, patty = [1], [1]
for i in range(N):
    size.append(size[i] * 2 + 3)
    patty.append(patty[i] * 2 + 1)

print(f(N, X))

Submission status: Wrong Answer

Solution code:
import math


# def burger_generator(n):
#     if n == 0:
#         return int("101", 2)
#     else:
#         lt = burger_generator(n-1)
#         x1 = 1 + (lt << 1)
#         length = int(math.log2(x1)) + 1
#         x1 = x1 + (lt << length + 1)
#         length = int(math.log2(x1)) + 1
#         return x1 + (1 << length)


def f(N, X):
    if X == 1:
        return 0
    if 1 < X <= 1 + size[N - 1]:
        return f(N - 1, X - 1)
    if X == 2 + size[N - 1]:
        return patty[N - 1] + 1
    if 2 + size[N - 1] < X <= 2 + 2 * size[N - 1]:
        return patty[N - 1] + 1 + f(N - 1, X - 2 - size[N - 1])
    if X == 3 + 2 * size[N - 1]:
        return 2 * patty[N - 1] + 1


N, X = map(int, input().split())
# burger = format(burger_generator(N), "b")
# print(burger[-K:].count("0"))
size, patty = [1], [1]
for i in range(N):
    size.append(size[i] * 2 + 3)
    patty.append(patty[i] * 2 + 1)

print(f(N, X))

Submission status: Wrong Answer

Solution code:
import math


# def burger_generator(n):
#     if n == 0:
#         return int("101", 2)
#     else:
#         lt = burger_generator(n-1)
#         x1 = 1 + (lt << 1)
#         length = int(math.log2(x1)) + 1
#         x1 = x1 + (lt << length + 1)
#         length = int(math.log2(x1)) + 1
#         return x1 + (1 << length)


def f(N, X):
    if X == 1:
        return 0
    if 1 < X <= 1 + size[N - 1]:
        return f(N - 1, X - 1)
    if X == 2 + size[N - 1]:
        return patty[N - 1] + 1
    if 2 + size[N - 1] < X <= 2 + 2 * size[N - 1]:
        return patty[N - 1] + 1 + f(N - 1, X - 2 - size[N - 1])
    if X == 3 + 2 * size[N - 1]:
        return 2 * patty[N - 1] + 1


N, X = map(int, input().split())
print(N, X)
# burger = format(burger_generator(N), "b")
# print(burger[-K:].count("0"))
size, patty = [1], [1]
for i in range(N):
    size.append(size[i] * 2 + 3)
    patty.append(patty[i] * 2 + 1)

print(f(N, X))

Submission status: Wrong Answer

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

a, p = [1], [0]
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())

def burger(n):
    if n == 0:
        return 'P'
    ans = 'B' + burger(n-1) + 'P' + burger(n-1) + 'B'
    return ans

print(burger(N))
eat = burger(N)[ : X]
print(eat)
print(eat.count('P'))

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
a=[(1,1)]
for _ in range(n-1):a+=[(a[-1][0]*2+3,a[-1][1]*2+1)]
s=0
for i,j in a[::-1]:
  if i<=x:
    x-=i;s+=j
    if x>=2:x-=1;s+=1
  x-=1
print(s)

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
a=[(1,1)]
for _ in range(n-1):
  a+=[(a[-1][0]*2+3,a[-1][1]*2+1)]
s=0
for i,j in a[::-1]:
  if i<=x:
    x-=i;s+=j
    if x>=1:x-=1;s+=1
  x-=1
print(s)

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
a=[(1,1)]
for _ in range(n-1):
  a+=[(a[-1][0]*2+3,a[-1][1]*2+1)]
s=0
for i,j in a[::-1]:
  x-=1
  if i<=x+1 and x!=0:
    x-=i;s+=j
    if x>=1:x-=1;s+=1
print(s)

Submission status: Wrong Answer

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

s=0
for k in range(1,len(a)*2+1):
  i,j = a[-k // 2]
  x -= k % 2
  if i <= x:
    x-=i;s+=j
    if x>=1:
      x-=1;s+=1

print(s)

Submission status: Wrong Answer

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

if a[-1][0] in (x,x-1):
  print(a[-1][1])
  exit()
a=a[:-1]
s=0
for k in range(1,len(a)*2+1):
  i,j = a[-k // 2]
  x -= (k+1) % 2
  if i <= x:
    x-=i;s+=j
    if x>=1:
      x-=1;s+=1

print(s)

Submission status: Wrong Answer

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

if a[-1][0] in (x,x-1):
  print(a[-1][1])
  exit()
a=a[:-1]
x-=1

s=0
for i,j in a[::-1]:
  x-=1
  if i<=x:
    x-=i;s+=j
    if x>=1:
      x-=1;s+=1
print(s)

Submission status: Wrong Answer

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

if a[-1][0] in (x,x-1):
  print(a[-1][1])
  exit()
a=a[:-1]
 
s=0
for i,j in a[::-1]:
  x-=1
  if i<=x:
    x-=i;s+=j
    if x>=1:
      x-=1;s+=1
print(s)

Submission status: Wrong Answer

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

if a[-1][0]==x:
  print(a[-1][1])
  exit()
if a[-1][0]==x-1:
  print(a[-1][1]-1)
  exit()
a=a[:-1]
 
s=0
for i,j in a[::-1]:
  x-=1
  if i<=x:
    x-=i;s+=j
    if x>=1:
      x-=1;s+=1
print(s)

Submission status: Wrong Answer

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

s=0
for i,j in a[::-1]:
  x-=1
  if i<=x:
    x-=i;s+=j
    if x>=1:
      x-=1;s+=1

print(s)

Submission status: Wrong Answer

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

if a[-1][0]==x:
  print(a[-1][1])
  exit()
a=a[:-1]

s=0
for i,j in a[::-1]:
  x-=1
  if i<=x:
    x-=i;s+=j
    if x>=1:
      x-=1;s+=1
print(s)

Submission status: Wrong Answer

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

if a[-1][0]==x:
  print(a[-1][1])
  exit()

s=0
for i,j in a[::-1]:
  x-=1
  if i<=x:
    x-=i
    s+=j
    if x>=1:
      x-=1
      s+=1
print(s)

Submission status: Wrong Answer

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

if a[-1][0]==x:
  print(a[-1][1])
  exit()

s=0
for i,j in a[::-1]:
  x-=1
  if i<=x:
    x-=i+1
    s+=j+1
    if x>=1:
      x-=1
      s+=1
print(s)

Submission status: Wrong Answer

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

if a[-1][0]==x:
  print(a[-1][1])
  exit()

s=0
for i,j in a[::-1]:
  x-=1
  if i<=x:
    x-=i+1
    s+=j+1
  if x>=1:
    x-=1
    s+=1
print(s)

Submission status: Wrong Answer

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

if a[-1][0]==x:
  print(a[-1][1])
  exit()

s=0
for i,j in a[::-1]:
  x-=1
  if i<=x:
    x-=i+1
    s+=j+1
print(s)

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
a=[(1,1)]
for _ in range(n):
  a+=[(a[-1][0]*2+3,a[-1][1]*2+1)]
s=0
for i,j in a[::-1]:
  if i<=x:
    x-=i+2
    s+=j+1
  else:
    x-=1
print(s)

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
a=[(1,1)]
for _ in range(n-1):
  a+=[(a[-1][0]*2+3,a[-1][1]*2+1)]
s=0
for i,j in a[::-1]:
  if i<=x:
    x-=i
    s+=j
print(s)

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
a=[(1,1)]
for _ in range(n):
  a+=[(a[-1][0]*2+3,a[-1][1]*2+1)]
s=0
for i,j in a[::-1]:
  if i<=x:
    x-=i
    s+=j
print(s)

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
c=1
a=[(1,1)]
while len(a) <= n:
  a+=[(a[-1][0]*2+3,a[-1][1]*2+1)]
s=0
for i,j in a[::-1]:
  if i<=x:
    x-=i
    s+=j
print(s)

Submission status: Wrong Answer

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

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

#print(B)

def bur(a,b):
    if a==0 :
        if b==0 :
            return 0
        else :
            return 1
    elif b<=1 :
        return 0
    elif b<=1+B[a-1][0]-1 :
        return bur(a-1,b-1)
    elif b<=1+B[a-1][0]+1 :
        return B[a-1][1]+1
    elif b<=1+B[a-1][0]+1+B[a-1][0]-1 :
        return B[a-1][1]+1+bur(a-1,b-2-B[a-1][0])
    elif b<=1+B[a-1][0]+1+B[a-1][0]+1 :
        return B[a-1][1]*2+1
    print(a)
    

print(bur(n,x))

Submission status: Wrong Answer

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

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

#print(B)

def bur(a,b):
    if a==0 :
        return 1
    elif b<=1 :
        return 0
    elif b<=1+B[a-1][0]-1 :
        return bur(a-1,b-1)
    elif b<=1+B[a-1][0]+1 :
        return B[a-1][1]+1
    elif b<=1+B[a-1][0]+1+B[a-1][0]-1 :
        return B[a-1][1]+1+bur(a-1,b-2-B[a-1][0])
    elif b<=1+B[a-1][0]+1+B[a-1][0]+1 :
        return B[a-1][1]*2+1
    print(a)
    

print(bur(n,x))

Submission status: Wrong Answer

Solution code:
def L(N):
    if N==0:
        return 1
    else:
        prev_L = L(N-1)
        return 1+prev_L+1+prev_L+1
def numP(N):
    if N==0:
        return 1
    else:
        prev_P = numP(N-1)
        return 2*prev_P+1
def eated_P(N,X):
    ans = 0
    fh=int(L(N)/2)
    if X<=0:
        return 0
    elif N==0:
        return 1
    elif fh<X:
        ans = numP(N-1)+1+eated_P(N-1,X-fh-1)
        return ans
    else:
        ans = eated_P(N-1,X-N+1)
        return ans
N,X = map(int,input().split())
print(eated_P(N,X))

Submission status: Wrong Answer

Solution code:
def L(N):
    if N==0:
        return 1
    else:
        prev_L = L(N-1)
        return 1+prev_L+1+prev_L+1
def numP(N):
    if N==0:
        return 1
    else:
        prev_P = numP(N-1)
        return 2*prev_P+1
def eated_P(N,X):
    ans = 0
    fh=int(L(2)/2)
    if X==0:
        return 0
    elif N==0:
        return 1
    elif fh<X:
        ans = numP(N-1)+1+eated_P(N-1,X-fh-1)
        return ans
    else:
        ans = eated_P(N-1,X-N-1)
        return ans
N,X = map(int, input().split())
print(eated_P(N,X))

Submission status: Wrong Answer

Solution code:

# coding: utf-8

# In[103]:


n,x = map(int, input().split())


# In[104]:


def p(n):
    return 2 ** (n+1) - 1
def b(n):
    return 2 ** (n+1) - 2
def l(n):
    return 2 ** (n+2) - 3


# In[109]:


def func(i, x):
    if x == 0:
        return 0
    elif x <= l(i-1) + 1:
        return func(i-1, x-1)
    elif x == l(i-1) + 2:
        return p(i-1) + 1
    elif x <= 2 * l(i-1) + 2:
        return p(i-1) + 1 + func(i-1, x - l(i-1) - 2)
    else:
        return 2 * p(n-1) + 1


# In[110]:


print(func(n,x))

Submission status: Wrong Answer

Solution code:

# coding: utf-8

# In[89]:


n,x = map(int, input().split())


# In[90]:


def p(n):
    return 2 ** (n+1) - 1
def b(n):
    return 2 ** (n+1) - 2
def l(n):
    return 2 ** (n+2) - 3


# In[99]:


def func(i, x):
    if x == 0:
        return 0
    elif x <= l(i-1) + 1:
        return func(i-1, x-1)
    elif x == l(i-1) + 2:
        return p(i-1) + 1
    elif x <= 2 * l(i-1) + 2:
        return p(i-1) + 1 + func(i-1, x - l(i-1) - 2)
    else:
        return p(n)


# In[100]:


print(func(n,x))

Submission status: Wrong Answer

Solution code:

# coding: utf-8

# In[89]:


n,x = map(int, input().split())


# In[90]:


def p(n):
    return 2 ** (n+1) - 1
def b(n):
    return 2 ** (n+1) - 2
def l(n):
    return 2 ** (n+2) - 3


# In[91]:


def func(i, x):
    if x == 0:
        return 0
    else:
        if i == 0:
            if x == 1:
                return 1
            else:
                return 0
        else:
            if x <= 2 ** (i+1) - 2:
                return func(i-1, x-1)
            else:
                return p(i-1) + 1 + func(i-1, x - (2 ** (i+1) - 2) - 1,)


# In[92]:


print(func(n,x))

Submission status: Wrong Answer

Solution code:
N,X=map(int,input().split())
Length=[1]
for i in range(1,51):
    Length.append(Length[i-1]*2+3)
def DP(N,point):
    if N == 0:
        return 1
    if point==1:
        return 0
    if 2<=point<=Length[N]//2:
        return DP(N-1,point-1)
    if point==Length[N]//2+1:
        return DP(N-1,point-2)+1
    if Length[N]//2+2<=point and\
            point <=Length[N]-1:
        return DP(N-1,point-Length[N-1]-2)+\
                DP(N-1,Length[N-1])
    if point==Length[N]:
        return DP(N-1,Length[N-1])*2+1
print(DP(N,X))

Submission status: Wrong Answer

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

# 厚み
L=[1]
for _ in range(50):
  L.append(L[-1]*2 + 3)
#print(L)
  
# patty
P=[1]
for _ in range(50):
  P.append(P[-1]*2+1)
#print(P)

def count_patty(N,X):
  if X==1:
    return 0
  
  if X==L[N]:
    return P[N]
  
  if L[N]<X:
    return P[N]
    
  if L[N-1]+1>=X:
    return count_patty(N-1,X-1)
    
  if L[N-1]+2==X:
    return P[N-1]+1
    
  if L[N-1]+2<X:
    return count_patty(N-1, X-L[N-1]-2) + P[N-1] + 1
    
print(count_patty(N,X))

Submission status: Wrong Answer

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

# 厚み
L=[1]
for _ in range(50):
  L.append(L[-1]*2 + 3)
#print(L)
  
# patty
P=[1]
for _ in range(50):
  P.append(P[-1]*2+1)
#print(P)
  
#memo[N][X]
memo=[[None for _ in range(50)] for _ in range(50)]
memo[0][0] = 1 

def count_patty(N=N,X=X):
  if X==1:
    return 0
  
  if X==L[N]:
    return P[N]
  
  if L[N]<X:
    return P[N]
    
  if L[N-1]+1>=X:
    return count_patty(N-1,X-1)
    
  if L[N-1]+2==X:
    return P[N-1]+1
    
  if L[N-1]+2<X:
    return count_patty(N-1, X-L[N-1]-2) + P[N-1] + 1
    
print(count_patty(N,X))

Submission status: Wrong Answer

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

if __name__=="__main__":
  n, x = input().split()
  a = [1]
  p = [1]
  for i in range(0, int(n)):
    a.append(a[i] * 2 + 3)
    p.append(p[i] * 2 + 1)
  print(md_burger(int(n), int(x)))

Submission status: Wrong Answer

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

if __name__=="__main__":
  n, x = input().split()
  a = [1]
  p = [1]
  for i in range(0, int(n)):
    a.append(a[i] * 2 + 3)
    p.append(p[i] * 2 + 1)
  print(md_burger(int(n), int(x)))

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
def layer(n):
    return 2 ** (n+2) - 3
def full(n):
    return 2 ** (n+1) - 2
def solve(n, x):
    if x <= 0:
        return 0
    if n == 0:
        return 1
    if x >= layer(n):
        return full(n)
    if x <= layer(n-1) + 1:
        return 1 + solve(n-1, x-1)
    else:
        return full(n-1) + solve(n-1, x - layer(n-1) - 2) + 1
print(x - solve(n,x))

Submission status: Wrong Answer

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

L = n
res = 0
while(1):
    if(L == 0):
        if(k==(n+1)):
            res += 1
        break
    bar = (n-L) + (((1<<(L+2))-3)>>1) + 1
#    print(str(L)+" "+str(k)+" "+str(bar))
    if k < bar:
        L -= 1  
    elif k == bar:
        res += (1<<L)
        break 
    else:
        res += (1<<L)
        
        k -= ((1<<(L+1)) -2)
        L -= 1
print(res)

Submission status: Wrong Answer

Solution code:
n = raw_input()
n,x = int(n.split(" ")[0]), int(n.split(" ")[1])

size = 1
np = 1
for i in range(n):
	size = 2*(size)+3
	np = 2*(np)+1
if x<=n:
	print(0)
else:
	print(int(round((np+1)*x/float(size))))

Submission status: Wrong Answer

Solution code:
n,x = map(int, input().split())
def burger(x):
    if x==0:
        return 'P'
    else:
        return 'B'+burger(x-1)+'P'+burger(x-1)+'B'
burger = burger(n)
print(burger[:x+1].count('P'))

Submission status: Wrong Answer

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

burger = ["P"]
for i in range(N+1):
    burger.append("B"+burger[i-1]+"P"+burger[i-1]+"B")
#print(burger[N + 1])
print(burger[N+1][0:X].count("P"))

Submission status: Wrong Answer

Solution code:
N,X=map(int,input().split())
def humberger(N):
    if N==0:
        return [1]
    else:
        return [0]+humberger(N-1)+[1]+humberger(N-1)+[0]
list1=humberger(N)
del list1[X:]
sum(list1)

Submission status: Wrong Answer

Solution code:
from functools import lru_cache
@lru_cache(maxsize=None)
def b(n):
    if n<1:return 1
    return b(n-1)*2+3
@lru_cache(maxsize=None)
def p(n):
    if n<1:return 1
    return p(n-1)*2+1
def solve(n,x):
    if n<1:return int(x>0)
    if x<=b(n-1):return(solve(n-1,x-1))
    return p(n-1)+solve(n-1,x-b(n-1)-2)+1
print(solve(*map(int,input().split())))

Submission status: Wrong Answer

Solution code:
n,x = map(int,input().split())
n_burgar = ["P"]
m=0
for i in range(0,n):
    m_burgar=[]
    for item in n_burgar:
        m_burgar.append(item)
    n_burgar.insert(m,"B")
    #for item in m_burgar:
     #   m=m+1
      #  n_burgar.insert(m,item)
    n_burgar.insert(m+1,"P")
    for item in m_burgar:
        m=m+1
        n_burgar.insert(m,item)
    n_burgar.insert(m+3,"B")
    m=0
for item in n_burgar:
    print(item)

Submission status: Wrong Answer

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

# B[L] = 1 + B[L-1] + 1 + B[L-1] + 1
# B[0] = 1
def Ber_memo(L,memo=[0]*(N+1)):
    if L == 0:
        return 1
    if memo[L] != 0:
        return memo[L]
    memo[L] = 2*Ber_memo(L-1) + 3
    return memo[L]

# P[L] = P[L-1] + 1 + P[L-1]
# P[L] = 1
def Patty_memo(L,memo=[0]*(N+1)):
    if L == 0:
        return 1
    if memo[L] != 0:
        return memo[L]
    memo[L] = 2*Patty_memo(L-1) + 1
    return memo[L]

def rec_memo(L=N,bottom=X):
    if bottom <= 1:
        return 0
    elif bottom <= 1 + Ber_memo(L-1):
        return rec_memo(L-1,bottom-1)
    elif bottom == 1 + Ber_memo(L-1) + 1:
        return Patty_memo(L-1) + 1
    elif bottom <= 1 + Ber_memo(L-1) + 1 + Ber_memo(L-1):
        return Patty_memo(L-1) + 1 + rec_memo(L-1,bottom-(1+Ber_memo(L-1)+1))
    elif bottom <= 1 + Ber_memo(L-1) + 1 + Ber_memo(L-1) + 1:
        return Patty_memo(L-1) + 1 + Patty_memo(L-1)

print(rec_memo())

Submission status: Wrong Answer

Solution code:
def eat(x,n):
    ans,p,b = 0,0,0
    while(n>0 and x>0):
        p = 2**(n+1)-1
        b = 2**(n+1)-2
        #xが半分より大きい場合に真ん中のpよりあとを考える
        if x>=(p+b+1)/2:
            #真ん中のpよりあとの部分
            x -= (p+b+1)/2
            ans += (p+1)/2
        n=n-1
    return ans

if __name__ == '__main__':
    n,x=map(int, input().split())
    p = 2**(n+1)-1
    b = 2**(n+1)-2
    if x<n:
        print(0)
    elif x>=(p+b)-n:
        print(p)
    else:
        print(int(eat(x,n)))

Submission status: Wrong Answer

Solution code:
N,X = map(long, raw_input().split())

def make(level):
  if level == 0:
    return [1]
  else:
    return [0] + make(level-1) + [1] + make(level-1) + [0]
  
print sum(make(N)[X-1:])

Submission status: Wrong Answer

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


def dfs(n, x):
    if x == 1:
        return 0
    elif 1 < x and x <= 1+na[n-1]:
        return dfs(n-1, x-1)
    elif 2+na[n-1] == x:
        return np[n-1]+1
    elif 2+na[n-1] < x and x <= 2+2*na[n-1]:
        return np[n-1]+1+dfs(n-1, x-2-na[n-1])
    elif x == 3+2*na[n-1]:
        return 2*np[n-1]+1

na = [1]
np = [1]
for i in range(N):
    na.append(na[-1]*2+3)
    np.append(np[-1]*2+1)
print(dfs(N, X))

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
def dfs(level,seq):
  if level==0:
    seq.append("P")
    return
  elif level>=1:
    seq.append("B")
    level-=1
    dfs(level,seq)
    seq.append("P")
    dfs(level,seq)
  return seq
seq=[] 
if N==K==1:
  print("1")
else:
  seq=dfs(N,seq)
  ans=seq[:K]
  ans=[i for i in ans if i=='P']
  print(len(ans))

Submission status: Wrong Answer

Solution code:
N,X = [int(x) for x in input().split()]
# num of Ps
B = [int((2**(n+1))-1) for n in range(N+1)]
# num of layers
C = [int((2**(n+2))-3) for n in range(N+1)]

def count(n,x):
    counter = 0
    center = int((C[n]+1)/2)
    if(x==1):
        counter = 0
    elif(x==C[n]):
        counter = B[n]
    elif(x==center):
        counter = int((B[n]+1)/2)
    elif(x<center):
        counter = count(n-1,x-1)
    elif(x>center):
        counter = int((B[n]+1)/2) + count(n-1,x-center)
    return counter

print(count(N,X))

Submission status: Wrong Answer

Solution code:
N,X = [int(x) for x in input().split()]
# num of Ps
B = [int((2**(n+1))-1) for n in range(N+1)]
# num of layers
C = [int((2**(n+2))-3) for n in range(N+1)]

def count(n,x):
    counter = 0
    center = int((C[n]+1)/2)
    if(x==1 or x==C[n]):
        counter = 0
    elif(x==center):
        counter = int((B[n]+1)/2)
    elif(x<center):
        counter = count(n-1,x-1)
    elif(x>center):
        counter = int((B[n]+1)/2) + count(n-1,x-center)
    return counter

print(count(N,X))

Submission status: Wrong Answer

Solution code:
n, x = (int(i) for i in input().split())

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

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

print(f(n, x))

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
def get_len(lv):
  m = 1
  for i in range(lv):
    m = m * 2 + 5
  return m  
def count_p(lv, p):
  if p == 0:return 0
  elif lv == 0:return 1
  m = get_len(lv)
  if p > (m-1)/2:
    return (m-1)/2 + 1 - count_p(lv, m-p)
  else:
    return count_p(lv-1,p-1)
print(int(count_p(n, x)))

Submission status: Wrong Answer

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

c = a[1]
res = 0

b = [[5,3,1]]
for i in range(1,a[0]+1):
    tmp = [b[i-1][0]*2+3,b[i-1][1]*2+1,i+1]
    b.append(tmp)

for i in range(a[0]-1,-1,-1):
    if b[i][0] <= c:
        c = c - b[i][0]
        res = res + b[i][1]
        if c > 0:
            c = c -1
            res = res + 1
    c = c - 1

if c > 0:
    res = res + c


print(res)

Submission status: Wrong Answer

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

c = a[1]
res = 0

b = [[5,3,1]]
for i in range(1,a[0]+1):
    tmp = [b[i-1][0]*2+3,b[i-1][1]*2+1,i+1]
    b.append(tmp)

for i in range(a[0]-1,-1,-1):
    print(b[i],c)
    if b[i][0] <= c:
        c = c - b[i][0]
        res = res + b[i][1]
        if c > 0:
            c = c -1
            res = res + 1
    c = c - 1

if c > 0:
    res = res + c


print(res)

Submission status: Wrong Answer

Solution code:
a = list(map(int, input().split()))
c = a[1]
res = 0

b = [[5,3,1]]
for i in range(1,a[0]+1):
    tmp = [b[i-1][0]*2+3,b[i-1][1]*2+1,i+1]
    b.append(tmp)

for i in range(a[0]-1,-1,-1):
    if b[i][0] < c:
        c = c - b[i][0] - 1
        res = res + b[i][1] + 1
    c = c - 1

if c > 0:
    res = res + c
print(res)

Submission status: Wrong Answer

Solution code:
a = list(map(int, input().split()))
c = a[1]
res = 0

b = [[5,3,1]]
for i in range(1,a[0]+1):
    tmp = [b[i-1][0]*2+3,b[i-1][1]*2+1,i+1]
    b.append(tmp)

for i in range(a[0]-1,-1,-1):
    if b[i][0] <= c:
        c = c - b[i][0] - 1
        res = res + b[i][1] + 1
    c = c - 1

if c > 0:
    res = res + c
print(res)

Submission status: Wrong Answer

Solution code:
a = list(map(int, input().split()))
c = a[1]
res = 0

b = [[5,3,1]]
for i in range(1,a[0]+1):
    tmp = [b[i-1][0]*2+3,b[i-1][1]*2+1,i+1]
    b.append(tmp)

for i in range(a[0]-1,-1,-1):
    if b[i][0] <= c:
        c = c - b[i][0] - 1
        res = res + b[i][1] + 1
    c = c - 1

if c == 1:
    res = res + 1


print(res)

Submission status: Wrong Answer

Solution code:
a = list(map(int, input().split()))
c = a[1]
res = 0

b = [[5,3,1]]
for i in range(1,a[0]+1):
    tmp = [b[i-1][0]*2+3,b[i-1][1]*2+1,i+1]
    b.append(tmp)

for i in range(a[0]-1,-1,-1):
    if b[i][0] < c:
        c = c - b[i][0] - 1
        res = res + b[i][1] + 1
    c = c - 1

if c == 1:
    res = res + 1


print(res)

Submission status: Wrong Answer

Solution code:
N, X = map(int, input(). split())
a, p = [1], [1]

for n in range(N):
    a.append(a[n]*2 + 3)
    p.append(p[n]*2 + 1)

def xmas(N, X):
    if N == 0:
        return 0 if X <= 0 else 1
    elif 0 <= X <= 1 + a[N-1]:
        return xmas(N-1, X-1)
    else :
        return p[N-1] + 1 + xmas(N-1, X-(a[N-1]+2))

print(xmas(N, X))

Submission status: Wrong Answer

Solution code:
N, X = list(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 check(n, x):
    if n == 0:
        if x <= 0:
            return 0
        else:
            return 1

    if x < 1 + a[n - 1]:
        return check(n - 1, x - 1)

    return p[n - 1] + 1 + check(n - 1, x - 2 - a[n - 1])


def main():
    print(check(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(2 * a[i] + 3)
    p.append(2 * p[i] + 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:
def m(n): # n次元バーガーの層数
    if n == 0:
        return 1
    else:
        a = 1
        for i in range(n):
            a = a * 2 + 3
        return a

def paty(n): # n次元バーガーのパティの数
    a = 1
    if n >= 1:
        for i in range(n):
            a = a * 2 + 1
    return a

def a(n, x): #これが答えを返す
    x = x - 1
    if x == 0:
        return 0
    elif x == m(n-1) + 1:
        return paty(n-1) + 1
    elif x > m(n-1) + 1:
        return paty(n-1) + 1 + a(n-1, x - m(n-1) - 1)
    else:
        n = n - 1
        return a(n, x)

n, x= map(int, input().split())
print(a(n, x))