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())
def patty(L):
# レベルLバーガーにパティがいくらあるか
    p = 1
    for i in range(L):
        p = 2 * p + 1
    return (p)
def vol(L):
# レベルLバーガーが何層か
    m = 1
    for i in range(L):
        m  = m * 2 + 3
    return (m)
def eated(L, X):
# レベルLバーガーを下からX層に何枚パティがあるか
    if L == 0:
        return 1
    m = vol(L)
    if X == 1:
        #print("下から１枚")
        return 0
    elif X == (m + 1) / 2:
        #print("ちょうど真ん中")
        #print(str(L-1) + "バーガーのパティ＋１枚")
        return patty(L-1) + 1
    elif X < (m + 1) / 2:
        #print("下半分")
        #print(str(L-1) + "バーガーを考える")
        return eated(L-1, X-1)
    else:
        #print("上半分")
        #print(str(L) + "バーガーのパティを上から" + str(X) + "枚食べたと考える")
        return patty(L) - eated(L, m - X)
print(eated(n, x))

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
pty = [[] for i in range(n + 1)]
lay = [[] for i in range(n + 1)]
pty[0] = 1
lay[0] = 1
for L in range(1, n + 1):
    pty[L] = 2 * pty[L - 1] + 1
    lay[L] = 2 * lay[L - 1 ] + 3
ans = 0
while x > 1:
    if x >= lay[L] + 1:
        x -= lay[L] + 1
        ans += pty[L] + 1
    elif x == lay[L]:
        x -= lay[L]
        ans += pty[L]
    else:
        L -= 1
        x -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
pty = [[] for i in range(n + 1)]
lay = [[] for i in range(n + 1)]
pty[0] = 1
lay[0] = 1
for L in range(1, n + 1):
    pty[L] = 2 * pty[L - 1] + 1
    lay[L] = 2 * lay[L - 1 ] + 3
ans = 0
x -= 1
while x > 0 and L >= 0 :
    if x >= lay[L] + 1:
        x -= lay[L] + 1
        ans += pty[L] + 1
    else:
        L -= 1
        x -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**8)

def eat(level, X):
    if X == 0:
        return 0
    if level == 0:
        return X
    if X <= T_array[level-1]:
        return eat(level-1, X-1)
    else:
        return P_array[level-1] + 1 + eat(level-1, min(X-T_array[level-1]-2, T_array[level-1]))


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

P_array = [0] * 51
B_array = [0] * 51
T_array = [0] * 51
P_array[0] = 1
B_array[0] = 0
T_array[0] = 1

for i in range(1, 51):
    P_array[i] = P_array[i-1]*2 + 1
    B_array[i] = B_array[i-1]*2 + 2
    T_array[i] = P_array[i] + B_array[i]

print(eat(N,X))

Submission status: Wrong Answer

Solution code:
def ans(n,x):
    if n == 0:
        if x == 1:
            return 0
        elif x == 2:
            return 1
        elif x == 3:
            return 2
        else:
            return 3
    else:
        if x == 1:
            return 0
        if 2 <= x <= 2**(n+1) -2:
            return ans(n-1,x-1)
        if x == 2**(n+1) -1:
            return 2**n - 1 + 1
        if 2**(n+1) <= x <= 2**(n+2) -4:
            return 2**n - 1 + 1 + ans(n-1,x-2**(n+1)+1)
        else:
            return 2 * (2**n - 1) + 1
        
N, X = map(int,input().split())

print(ans(N,X))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


def solve_p(N, X):
    if N==0:
      if X<=0:
        return 0
      else:
        return 1
    else:
        if X == (nums[N]) // 2 +1:
            return (p_count[N]+1) // 2
        elif X < nums[N] // 2:
            return solve_p(N - 1, X - 1)
        else:
            return p_count[N-1]+1+solve_p(N-1, X-(nums[N]+1)//2)


print(solve_p(N, X))
"""
ans = 0
for i, n in enumerate(nums[:-1]):
    if X == n:
        ans += p_count[i]
        break
    elif X > n // 2:
        X -= p_count[i]//2
        ans += p_count[i] // 2
    elif X == n // 2:
        ans += (p_count[i] + 1) // 2
        break
# print(ans)

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

print(burger[N])

print(burger[N][:x].count("P"))
"""

Submission status: Wrong Answer

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


def solve_p(N, X):
    if N==0:
      if X<=0:
        return 0
      else:
        return 1
    else:
        if X == (nums[N]) // 2:
            return (p_count[N]+1) // 2
        elif X < nums[N] // 2:
            return solve_p(N - 1, X - 1)
        else:
            return p_count[N-1]+1+solve_p(N-1, X-(nums[N]+1)//2)


print(solve_p(N, X))
"""
ans = 0
for i, n in enumerate(nums[:-1]):
    if X == n:
        ans += p_count[i]
        break
    elif X > n // 2:
        X -= p_count[i]//2
        ans += p_count[i] // 2
    elif X == n // 2:
        ans += (p_count[i] + 1) // 2
        break
# print(ans)

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

print(burger[N])

print(burger[N][:x].count("P"))
"""

Submission status: Wrong Answer

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


def solve_p(N, X):
    if X <= 1:
        return 0
    elif N == 0:
        return 1
    else:
        if X == (nums[N]) // 2:
            return (p_count[N]+1) // 2
        elif X < nums[N] // 2:
            return solve_p(N - 1, X - 1)
        else:
            return p_count[N-1]+1+solve_p(N-1, X-(nums[N]+1)//2)


print(solve_p(N, X))
"""
ans = 0
for i, n in enumerate(nums[:-1]):
    if X == n:
        ans += p_count[i]
        break
    elif X > n // 2:
        X -= p_count[i]//2
        ans += p_count[i] // 2
    elif X == n // 2:
        ans += (p_count[i] + 1) // 2
        break
# print(ans)

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

print(burger[N])

print(burger[N][:x].count("P"))
"""

Submission status: Wrong Answer

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


def solve_p(N, X):
    if X <= 0:
        return 0
    elif N == 0:
        return 1
    else:
        if X == (nums[N]) // 2:
            return (p_count[N]+1) // 2
        elif X < nums[N] // 2:
            return solve_p(N - 1, X - 1)
        else:
            return p_count[N-1]+1+solve_p(N-1, X-(nums[N]+1)//2)


print(solve_p(N, X))
"""
ans = 0
for i, n in enumerate(nums[:-1]):
    if X == n:
        ans += p_count[i]
        break
    elif X > n // 2:
        X -= p_count[i]//2
        ans += p_count[i] // 2
    elif X == n // 2:
        ans += (p_count[i] + 1) // 2
        break
# print(ans)

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

print(burger[N])

print(burger[N][:x].count("P"))
"""

Submission status: Wrong Answer

Solution code:
def putty():
    N,X = map(int,input().split())
    ans = 0

    for i in range(1,N+1)[::-1]:
        width = 2**(i+2)-3
        if X <= i:   return ans
        elif X >= width - i:    return ans + 2**(i+1)-1
        else:
            mid = (width + 1) // 2
            if X == mid:    return ans + 2**(i)
            elif X < mid:   X -= 1 
            else:
                X -= 2**(i+1)-3 + 2 
                ans += 2**(i)

print(putty())

Submission status: Wrong Answer

Solution code:
n , x = map(int, input().split())
# ABCの長さ
a = [1]
for i in range(n):
    a.append(a[i] * 2 + 3)

# パティの枚数
p = [1]
for i in range(n):
    p.append(p[i] * 2 + 1)

def f(n, x):
    if n == 0:
        return 0 if x <= 0 else 1
    elif x == 1:
        return 1
    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 f(n - 1, x - 2 - a[n - 1]) + p[n-1] + 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())
# ABCの長さ
a = [1]
for i in range(n):
    a.append(a[i] * 2 + 3)

# パティの枚数
p = [1]
for i in range(n):
    p.append(p[i] * 2 + 1)

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
from math import *
from itertools import *
from collections import *
from functools import *
try:
    from math import gcd
except Exception:
    from fractions import gcd



def solve(N: int, X: int):
    a, p = [1], [1]
    for i in range(N):
        a.append(a[i] * 2 + 3)
        p.append(p[i] * 2 + 1)

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

    return _f(N, X)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    result = solve(N, X)
    print(result)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
from math import *
from itertools import *
from collections import *
from functools import *
try:
    from math import gcd
except Exception:
    from fractions import gcd



def solve(N: int, X: int):
    a, p = [1], [1]
    for i in range(N):
        a.append(a[i] * 2 + 3)
        p.append(p[i] * 2 + 1)

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

    return _f(N, X)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    result = solve(N, X)
    print(result)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
l = [1]
for i in range(1, n+1):
    if len(l) <= x:
        pre_l = l
        l = [0] + l
        l = l + list(reversed(pre_l)) + [1]
if len(l) >= x:
    print(sum(l[:x-1]))
else:
    print(sum(l))

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
l = [1]
for i in range(1, n+1):
    if len(l) <= x:
        pre_l = l
        l = [0] + l
        l = l + list(reversed(pre_l)) + [1]
print(sum(l[:x-1]))

Submission status: Wrong Answer

Solution code:
p = lambda n:2**(n+1)-1
a = lambda n:2**(n+2)-3


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

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

Submission status: Wrong Answer

Solution code:
p = lambda n:2**(n+1)-1
a = lambda n:2**(n+2)-3


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

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun May 19 16:57:17 2019

@author: Yamazaki Kenichi
"""

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

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

ans = 0
for i in range(2,N+2):
    if X - (dp[-i][1] + 2) >= 0:
        ans += dp[-i][0] + 1
        X -= (dp[-i][1] + 2)
#        print(ans,X,dp[-i])
    else:
        X -= 1
#        print(ans,X,dp[-i])
    if i == N+1 and X == 1:
        ans += 1
#        print(ans,X,dp[-i])
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun May 19 16:57:17 2019

@author: Yamazaki Kenichi
"""

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

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

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun May 19 16:57:17 2019

@author: Yamazaki Kenichi
"""

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

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

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun May 19 16:57:17 2019

@author: Yamazaki Kenichi
"""

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

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

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun May 19 16:57:17 2019

@author: Yamazaki Kenichi
"""

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

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

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

Submission status: Wrong Answer

Solution code:
def bread_cnt(lev):
  return 2**(lev+1) - 2

def patty_cnt(lev):
  return 2**(lev+1) - 1

def burger_cnt(lev):
  return 2**(lev+2) - 3

def solve(n, x):
  return _solve(n, x, 0)
  
def _solve(n, x, p):
  total_s = burger_cnt(n)
  mid = (total_s+1)//2
  
  if x<=1:
    return p
  elif 1 < x and x <= mid:
    reach_mid = 1 if x==mid else 0
    return _solve(n-1, x-1-reach_mid, p+reach_mid)
  elif mid < x and x < total_s:
    return _solve(n-1, x-2-burger_cnt(n-1), p+1+patty_cnt(n-1))
  elif x == total_s:
    return p+patty_cnt(n)

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

Submission status: Wrong Answer

Solution code:
def bread_cnt(lev):
  return 2**(lev+1) - 2

def patty_cnt(lev):
  return 2**(lev+1) - 1

def burger_cnt(lev):
  return 2**(lev+2) - 3

def solve(n, x):
  return _solve(n, x, 0)
  
def _solve(n, x, p):
  total_s = burger_cnt(n)
  
  if x==1:
    return p
  elif 1 < x and x < (total_s+1)//2:
    return _solve(n-1, x-1, p)
  elif x == (total_s+1)//2:
    return patty_cnt(n-1) + 1
  elif (total_s+1)//2 < x and x < total_s:
    return _solve(n-1, x-2-burger_cnt(n-1), p+1+patty_cnt(n-1))
  elif x == total_s:
    return p+patty_cnt(n)


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

Submission status: Wrong Answer

Solution code:
def bread_cnt(lev):
  return 2**(lev+1) - 2

def patty_cnt(lev):
  return 2**(lev+1) - 1

def burger_cnt(lev):
  return 2**(lev+2) - 3

def solve(n, x):
  return _solve(n, x, 0)
  
def _solve(n, x, p):
  total_s = burger_cnt(n)
  
  if x==1:
    return p
  elif 1 < x and x <= (total_s+1)//2:
    reach_mid = 1 if x==(total_s+1)//2 else 0
    return _solve(n-1, x-1-reach_mid, p+reach_mid)
  elif (total_s+1)//2 < x and x < total_s:
    return _solve(n-1, x-2-burger_cnt(n-1), p+1+patty_cnt(n-1))
  elif x == total_s:
    return p+patty_cnt(n)


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

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
import sys
sys.setrecursionlimit(10000000)

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

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
import sys
sys.setrecursionlimit(10000000)

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

Submission status: Wrong Answer

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

b = [[1,1]]

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

print(b)

ans = 0
for i in range(len(b)):
    if x >= b[-1-i][0]:
        x -= b[-1-i][0]
        ans += b[-1-i][1]
        if x > 0:
            x-=1
            ans += 1
        if x>=b[-1-i][0]:
            x -= b[-1 - i][0]
            ans += b[-1 - i][1]
            break
    x-=1
    if x<=0:
        break

print(ans)

Submission status: Wrong Answer

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

b = [[1,1]]

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

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

print(ans)

Submission status: Wrong Answer

Solution code:

def count(N):
    pn = 2**(N+1)-1 #パテ
    bn = 2**(N+1)-2 #バン
    rn = pn + bn    #バーガー枚数(右端)
    return pn, bn, rn
    
if __name__ == "__main__":
    N, X = map(int, input().split())
    pn,bn,rn = count(N)
    mid = (1+rn)//2
    cnt = 0
    # Xの位置関係で場合分け
    while N > 0:
        # print(X,"l m r",1,mid,rn)
        # print("cnt",N,cnt)
        pn_prev, bn_prev, rn_prev = count(N-1)

        if X == 1:
            cnt -= 1
            break
        elif X == mid:
            cnt +=  pn_prev
            break
        elif rn == X:
            cnt += 2*pn_prev + 1
            break
        elif 1 < X < mid:
            r = mid
        elif mid < X < rn:
            cnt += pn_prev + 1
            X -= (mid+1)

        pn, bn, rn = pn_prev,bn_prev,rn_prev
        mid = (1+rn)//2
        N -= 1
    print(cnt+1) #0段目のパテ

Submission status: Wrong Answer

Solution code:

def count(N):
    pn = 2**(N+1)-1 #パテ
    bn = 2**(N+1)-2 #バン
    rn = pn + bn    #バーガー枚数(右端)
    return pn, bn, rn
    
if __name__ == "__main__":
    N, X = map(int, input().split())
    pn,bn,rn = count(N)
    mid = (1+rn)//2
    cnt = 0
    # Xの位置関係で場合分け
    while N > 0:
        # print(X,"l m r",1,mid,rn)
        # print("cnt",N,cnt)
        pn_prev, bn_prev, rn_prev = count(N-1)

        if X == 1:
            break
        elif X == mid:
            cnt +=  pn_prev
            break
        elif rn == X:
            cnt += 2*pn_prev + 1
            break
        elif 1 < X < mid:
            r = mid
        elif mid < X < rn:
            cnt += pn_prev + 1
            X -= (mid+1)

        pn, bn, rn = pn_prev,bn_prev,rn_prev
        mid = (1+rn)//2
        N -= 1
    print(cnt+1) #0段目のパテ

Submission status: Wrong Answer

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


def main(n, x):
    if n == 0:
        if x == 0:
            return 1
        else:
            return 0
    if x == 0:
        return 0
    if x == 2 ** (n + 1) - 2:
        return 2 ** n
    if x < 2 ** (n + 1) - 2:
        return main(n - 1, x - 1)
    return 2 ** n + main(n - 1, x - (2 ** (n + 1) - 1))


print(main(n, x))

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
import numpy as np


def burger(num):
    if num == 1:
        return np.array([1, 3, 1])
    last_burger = burger(num - 1)
    return np.concatenate((last_burger[0] + 1, last_burger[1:], 1, last_burger[:-1], last_burger[-1] + 1), axis=None)


def main(n, x):
    burger_n = burger(n)
    print(burger_n)

    i, p, eaten = 0, 0, 0

    while eaten < x:
        eaten += burger_n[i]
        if i % 2 == 1:
            p += burger_n[i]
        i += 1

    if i % 2 == 0:
        p -= (eaten - x)

    print(p)


main(n, x)

Submission status: Wrong Answer

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


def f(n):
    # レベルnの総数
    if n == 0:
        return 1
    else:
        return 2 * f(n - 1) + 3


def g(n):
    # レベルnのpの数
    if n == 0:
        return 1
    else:
        return 2 * g(n - 1) + 1


def dfs(n, x):
    # 総数
    m = f(n)
    # 真ん中
    a = (m + 1) // 2

    if n == 0 or x == 1:
        return 0
    elif x < a:
        return dfs(n - 1, x - 1)
    elif x == a:
        return g(n - 1) + 1
    elif x >= a:
        return g(n - 1) + 1 + dfs(n - 1, x - a)
    elif x == m:
        return 2 * g(n - 1) + 1


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

Submission status: Wrong Answer

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


def f(n):
    # レベルnの総数
    if n == 0:
        return 1
    else:
        return 2 * f(n - 1) + 3


def g(n):
    # レベルnのpの数
    if n == 0:
        return 1
    else:
        return 2 * g(n - 1) + 1


def dfs(n, x):
    # 総数
    m = f(n)
    # 真ん中
    a = (m + 1) // 2

    if n == 0 or x == 1:
        return 0
    elif x < a:
        return dfs(n - 1, x - 1)
    elif x == a:
        return g(n - 1) + 1
    elif x >= a:
        return g(n - 1) + 1 + dfs(n - 1, x - a)
    elif x == m:
        return g(n - 1)


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

Submission status: Wrong Answer

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

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

def B(n): return 2**(n+1) - 1 # returns number of buns in level n


def eat(neat,level):

    if neat == 1:
        return 0

    t = thickness[level]
    center = t//2 + 1

    if neat == t:
        return B(level)

    elif neat < center:
        return eat(neat-1, level-1)

    elif neat == center:
        return 1 + B(level-1)

    else: # neat > center
        return 1 + B(level-1) + eat(neat - center, level-1)

print(eat(X, N))

Submission status: Wrong Answer

Solution code:
N, X = [int(item) for item in input().split()]
ar = [None] * (N + 1)
pr = [None] * (N + 1)
ar[0], pr[0] = 1, 1
for i in range(N):
  ar[i+1] = 2*ar[i]+3
  pr[i+1] = 2*pr[i]+1
ans = 0
while X != 1:
  if ar[N-1] + 2 == X:
    ans += pr[N-1] + 1
    break
  elif ar[N] == X:
    ans += pr[N]
    break
  elif ar[N-1] + 2 < X:
    ans += pr[N-1] + 1
    X = X - ar[N-1] - 2
  else:
    X -= 1
  N -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
N, X = [int(item) for item in input().split()]
ar = [None] * (N + 1)
pr = [None] * (N + 1)
ar[0], pr[0] = 1, 1
for i in range(N):
  ar[i+1] = 2*ar[i]+3
  pr[i+1] = 2*pr[i]+1
ans = 0
while X != 1:
  if ar[N-1] + 2 == X:
    ans += pr[N-1] + 1
    break
  elif ar[N] == X:
    ans += pr[N]
    break
  elif ar[N-1] + 2 < X:
    ans += pr[N-1] + 1
    X = X - ar[N-1] - 2
  N -= 1

print(ans)

Submission status: Wrong Answer

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

layer_size = [1]
P_cnt = [1]

for n in range(1,51):
    layer_size.append(layer_size[-1]*2+3)
    P_cnt.append(P_cnt[-1]*2+1)
    
def solve(level,x):
    if x == 1:
        return 0
    l = layer_size[level-1]
    p = P_cnt[level-1]
    if x <= 1+l:
        return solve(level-1,x-1)
    elif x == l+2:
        return p+1
    elif x <= 2*l+2:
        return p+1+solve(level-1,x-l-2)
    else:
        return 2*p+1

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

Submission status: Wrong Answer

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

n_sum= X
answer = [0]
def saiki(layer,n_sum,sum_p):
    # print(layer,n_sum,sum_p)
    # if layer == 0:
    #     answer[0] = sum_p
    #     return
    if layer == 1:
        if n_sum == 1:
            answer[0] = sum_p
        elif n_sum == 2:
            answer[0] = sum_p+1
        elif n_sum ==3:
            answer[0] = sum_p+2
        else:
            answer[0] = sum_p+3
        return

    ##現layerの合計を計算
    layer_sum = 2**(layer+2)-3
    ##前のlayerの合計を計算
    pre_layer_sum = 2**(layer+1)-3
    pre_p_sum = 2**(layer)-1
    #もし左側
    if n_sum  < layer_sum //2 +1 :
        # print("left")
        n_sum -= 1
        saiki(layer-1,n_sum,sum_p)
    
    else:
        # print("right")
        n_sum -= (pre_layer_sum+2)
        sum_p += (1+pre_p_sum)
        saiki(layer-1,n_sum,sum_p)

saiki(N,X,0)

print(answer[0])

Submission status: Wrong Answer

Solution code:
def patty(n,x):
    if x == 0:
        return 0
    elif n == 0:
        #print(n,x,1)
        return 1
    elif x == 1 and n > 0:
        return 0
    num = 2 ** (n+2) - 3
    pre_num = 2 ** (n+1) - 3
    if x == num:
        #print(n,x,2 * patty(n-1,pre_num) + 1)
        return 2 * patty(n-1,pre_num) + 1
    elif x > pre_num + 1:
        #print(n,x,patty(n-1,pre_num) + 1 + patty(n-1,x - pre_num - 2))
        return patty(n-1,pre_num) + 1 + patty(n-1,x - pre_num - 2)
    elif x == pre_num + 1:
        #print(n,x,patty(n-1,pre_num) + 1)
        return patty(n-1,pre_num) + 1
    else:
        #print(n,x,patty(n-1,x-1))
        return patty(n-1,x-1)

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

print(patty(n,x))

Submission status: Wrong Answer

Solution code:
def patty(n,x):
    if x == 0:
        return 0
    elif n == 0:
        #print(n,x,1)
        return 1
    num = 2 ** (n+2) - 3
    pre_num = 2 ** (n+1) - 3
    if x == num:
        #print(n,x,2 * patty(n-1,pre_num) + 1)
        return 2 * patty(n-1,pre_num) + 1
    elif x > pre_num + 1:
        #print(n,x,patty(n-1,pre_num) + 1 + patty(n-1,x - pre_num - 2))
        return patty(n-1,pre_num) + 1 + patty(n-1,x - pre_num - 2)
    elif x == pre_num + 1:
        #print(n,x,patty(n-1,pre_num) + 1)
        return patty(n-1,pre_num) + 1
    else:
        #print(n,x,patty(n-1,x-1))
        return patty(n-1,x-1)

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

print(patty(n,x))

Submission status: Wrong Answer

Solution code:
N,X=map(int,input().split())
def an(n):
    return 2**(n+1)-1
def bn(n):
    return 2**(n+2)-3
ans=0
while(N):
    if X==0:

        print(ans)
        quit()
    if X==bn(N):
        ans+=an(N)
        print(ans)
        quit()
    if X<=(bn(N)-1)/2:
        X-=1
        N-=1
    elif X==(bn(N)-1)/2+1:
        ans+=an(N-1)+1
        print(ans)
        quit()
    else:
        X=X-(bn(N-1)+2)
        ans+=an(N-1)+1
        N-=1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

nx = input().split()
n = int(nx[0])
x = int(nx[1])
count = 0


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

pcountlist = []
for i in range(n + 1):
    if i == 0:
        pcountlist.append(1)
    else:
        pcountlist.append(pcountlist[-1] * 2 + 1)


def incr_count(nn, xx):
    global count

    if nn == 0:
        if xx > 0:
            count += 1
        return

    if xx <= 1:
        pass
    if 1 < xx and xx <= lenlist[nn] // 2:
        incr_count(nn - 1, xx - 1)
    if xx == lenlist[nn] // 2:
        count += pcountlist[nn - 1]
    if lenlist[nn] // 2 < xx:
        count += pcountlist[nn - 1]
        count += 1
        incr_count(nn - 1, xx - lenlist[nn] // 2 - 1)


incr_count(n, x)
print(count)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(100000000)

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

height=[-1]*51
niku=[-1]*51
height[0]=1
niku[0]=1

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

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

    if x < 1+height[l-1]+1:
        return rec(l-1, x-1)
    elif x == 1+height[l-1]+1:
        return 1 + niku[l-1]
    else:
        return niku[l-1] + 1 + rec(l-1, x-height[l-1]-2)
print(rec(N, X))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(100000000)

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

height=[-1]*51
niku=[-1]*51
height[0]=1
niku[0]=1

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

def rec(l, x):
    if x==1 and l==0: return 1
    if x<=0: return 0
    if x < 1+height[l-1]+1:
        return rec(l-1, x-1)
    elif x == 1+height[l-1]+1:
        return 1 + niku[l-1]
    else:
        return niku[l-1] + 1 + rec(l-1, x-height[l-1]-2)
print(rec(N, X))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(100000000)

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

height=[-1]*51
niku=[-1]*51
height[0]=1
niku[0]=1

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

def rec(l, x):
    if x<=1:return 0
    if x < 1+height[l-1]+1:
        return rec(l-1, x-1)
    elif x == 1+height[l-1]+1:
        return 1 + niku[l-1]
    else:
        return niku[l-1] + 1 + rec(l-1, x-height[l-1]-2)
print(rec(N, X))