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=[int(i) for i in input().split()]
p=[1]
b=[0]
z=[]
for i in range(n):
  p.append(p[i]*2+1)
  b.append(b[i]*2+2)
  z.append(p[i]+b[i])
ans=0
ici=1
for i in range(n-1, -1, -1):
  if x-ici>z[i]+1:
    ici+=z[i]+2
    ans+=p[i]+1
  elif x-ici<z[i]+1:
    ici+=1
  else:
    ans+=p[i]
    break
print(ans)

Submission status: Wrong Answer

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

layer = [1]
num_of_P = [1]
result = 0

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

layer.append(layer[-1] * 2 + 3)

while num_of_P:
    if layer[-1] // 2 + 1 > X:
        X -= 1
    else:
        X -= layer[-1] // 2 + 1
        result += num_of_P[-1] + 1

    del layer[-1]
    del num_of_P[-1]

print(result)

Submission status: Wrong Answer

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


def search(level, eat_num):
    if eat_num == 0:
        if eat_num <= 0:
            return 0
        else:
            return 1

    elif eat_num == 1:
        return 0

    elif 1 < eat_num <= pow(2, level + 1) - 2:
        return search(level - 1, eat_num - 1)

    elif eat_num == pow(2, level + 1) - 1:
        return pow(2, level)

    elif pow(2, level + 1) - 1 < eat_num <= pow(2, level + 2):
        return pow(2, level) + search(level - 1, eat_num - (pow(2, level + 1) - 1))

    elif X == pow(2, level + 2) + 1:
        return pow(2, level + 1) - 1
    
    else:
        return pow(2, level + 1) - 1


print(search(level=N, eat_num=X))

Submission status: Wrong Answer

Solution code:
import numpy as np

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

a = 1
p = 1
a_list = [1]
p_list = [1]
for i in range(N+1):
    a = 2 * a + 3
    p = 2 * p + 1
    a_list.append(a)
    p_list.append(p)


def f(N, X):
    ai_1 = a_list[N-1]
    if N == 1:
        if X <= 4:
            out = X - 1
        else: 
            assert X == 5
            out = 4
    elif X == 1:
        out = 0
    elif 2 <= X and X <= 1+ai_1:
        out = f(N-1, X-1)
    elif X == 2 + ai_1:
        out = p_list[N-1] + 1
    elif 3 + ai_1 <= X and X <= 2 + 2*ai_1:
        out = p_list[N-1] + 1 + f(N-1, X - 2 - a_list[N-1])
    else:
        assert X == 3+ 2*ai_1
        out = p_list[N]
    return out


print(f(N, X))

Submission status: Wrong Answer

Solution code:
import numpy as np

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

a = 1
p = 1
a_list = [1]
p_list = [1]
for i in range(N+1):
    a = 2 * a + 3
    p = 2 * p + 1
    a_list.append(a)
    p_list.append(p)


def f(N, X):
    ai_1 = a_list[N-1]
    if X == 1:
        out = 0
    elif 2 <= X and X <= 1+ai_1:
        out = f(N-1, X-1)
    elif X == 2 + ai_1:
        out = p_list[N-1] + 1
    elif 3 + ai_1 <= X and X <= 2 + 2*ai_1:
        out = p_list[N-1] + 1 + f(N-1, X - 2 - a_list[N-1])
    elif X == 3+ 2*ai_1:
        out = p_list[N]
    else:
        raise Exception("bad")
    return out


print(f(N, X))

Submission status: Wrong Answer

Solution code:
import numpy as np

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

a = 1
p = 1
a_list = [1]
p_list = [1]
for i in range(N+1):
    a = 2 * a + 3
    p = 2 * p + 1
    a_list.append(a)
    p_list.append(p)


def f(N, X):
    ai_1 = a_list[N-1]
    if X == 1:
        out = 0
    elif 2 <= X and X <= 1+ai_1:
        out = f(N-1, X-1)
    elif X == 2 + ai_1:
        out = p_list[N-1] + 1
    elif 3 + ai_1 <= X and X <= 3 + 2*ai_1:
        out = p_list[N-1] + 1 + f(N-1, X - 2 - a_list[N-1])
    else:
        out = p_list[N]
    return out


print(f(N, X))

Submission status: Wrong Answer

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

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

#print "p:::",p
#print "a::::",a

X-=1

ans=0
def f(N,X):
	global ans
#	print "f (",N ," , ", X ," ) " ,ans

	if X<0:
		return 0		
	elif N==0:
		return 1
	elif X>=a[N]/2:
		X-=(a[N-1]+2)
		ans+=p[N-1]+1
		f(N-1,X)
	else:
		X-=1
		f(N-1,X)

f(N,X)

print ans

Submission status: Wrong Answer

Solution code:
a=[]
a=input().split(" ")
N=int(a[0])
X=int(a[1])
L=[1]
b=[1]
c=[0]
e=[1]
L=c+L+b+L+c
for List in range(0,N):
    #L=nの時のリスト=[0]+[L=n-1の時のリスト]+[1]+[L=n-1の時のリスト]+[0]
    List=L
    L=c+L+b+L+c
p=[]
for i in range(0,X):#「全体の配列L」から「0からX-1番目までの数を抜き出した新しい配列q」を作る
    q=L[i]
    p.append(q)
r=sum(p)
print(r)

Submission status: Wrong Answer

Solution code:
def where_X(X, b, p, n):
  l = b[n]+1
  if X == 0:
    return [0, 0, 0]
  elif 0 < X < l:
    return [1, 1, 0]
  elif X == l:
    return [2, 0, 1+p[n]]
  elif l < X < 2*l:
    return [3, 2+b[n], 1+p[n]]
  elif X == 2*l:
    return [4, 0, 1+2*p[n]]

N, X = map(int, input().split())
X -= 1
p = [1]*(N+1)
b = [1]*(N+1)

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

now_N = N-1
result = 0
start = 0
for i in range(N-1):
  ret_X = where_X(X-start, b, p, now_N)
  start += ret_X[1]
  result += ret_X[2]
  if ret_X[0] % 2 == 0:
    break  
  now_N -= 1

print(result)

Submission status: Wrong Answer

Solution code:
import math

def burger_size(n):
    return 2**(n + 2) - 3

def num_of_patty(n):
    return 2**(n + 1) - 1

def calc(n, x):
    if n == 0:
        return 1
    if x <= n:
        return 0
    if x == burger_size(n):
        return num_of_patty(n)
    
    center = math.floor((burger_size(n) + 1) / 2)
    if x < center:
        return calc(n - 1, x - 1)
    elif x > center:
        return num_of_patty(n - 1) + 1 + calc(n - 1, x - burger_size(n - 1) - 2)
    else:
        return num_of_patty(n - 1) + 1

Submission status: Wrong Answer

Solution code:
n, x = map(int,input().split())
def ABC115D(n,x):
    if n == 0:
        return 1
    elif x == 1:
        return 0
    elif x >= 2**(n+1)-1:
        return ABC115D(n-1,x-2**(n+1)+1) + 2**n
    else:
        return ABC115D(n-1,x-1)
print(ABC115D(n,x))

Submission status: Wrong Answer

Solution code:
n, x = map(int,input().split())
def ABC115D(n,x):
    if n == 0:
        return 1
    elif x == 1:
        return 0
    elif x >= 2**(n+1)-1:
        return ABC115D(n-1,x-2**(n+1)+1) + 2**n
    elif x == 2**(n+1)-2:
        return 2**n - 1
    else:
        return ABC115D(n-1,x-1)
print(ABC115D(n,x))

Submission status: Wrong Answer

Solution code:
n, x = map(int,input().split())
def ABC115D(n,x):
    if x == 1:
        return 0
    elif n == 0:
        return 1
    elif x >= 2**(n+1)-1:
        return ABC115D(n-1,x-2**(n+1)+1) + 2**n
    elif x == 2**(n+1)-2:
        return 2**n - 1
    else:
        return ABC115D(n-1,x-1)
print(ABC115D(n,x))

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

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

def burger(level: int, x: int):
    if level == 0:
        return 0
    
    if x == 1:
        return 0
    
    elif 1 < x <= 1+a[level-1]:
        return burger(level-1, x-1)
    
    elif x == 2+a[level-1]:
        return p[level-1] + 1
    
    elif 2+a[level-1] < x <= 2+2*a[level-1]:
        return p[level-1] + 1 + burger(level-1, x-1-a[level-1]-1)
    
    elif x == 3+2*a[level-1]:
        return 2*p[level-1] + 1
    
n,x = li()    
print(burger(n,x))

Submission status: Wrong Answer

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

atusa=[1]
Pkosu=[1]
for i in range(n):
  atusa.append(atusa[-1]*2+3)
  Pkosu.append(Pkosu[-1]*2+1)

def getPkosu(level,num):
  if level==0:
    return 1
  elif num==1 or num==0:
    return 0
  elif num <= atusa[level-1]+1:
    return getPkosu(level-1,num-1)
  elif num == atusa[level-1]+2:
    return Pkosu[level-1]+1
  elif num < atusa[level-1]*2+2:
    return Pkosu[level-1]+getPkosu(level-1,num-(2+atusa[level-1]))+1
  else:
    return Pkosu[level-1]*2

print(getPkosu(n,x))
#print(atusa)
#print(Pkosu)

Submission status: Wrong Answer

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

atusa=[1]
Pkosu=[1]
for i in range(n):
  atusa.append(atusa[-1]*2+3)
  Pkosu.append(Pkosu[-1]*2+1)

def getPkosu(level,num):
  if level==0:
    return 1
  elif num==1:
    return 0
  elif num <= atusa[level-1]+1:
    return getPkosu(level-1,num-1)
  elif num == atusa[level-1]+2:
    return Pkosu[level-1]+1
  elif num < atusa[level-1]*2+2:
    return Pkosu[level-1]+getPkosu(level-1,num-(2+atusa[level-1]))+1
  else:
    return Pkosu[level-1]*2

print(getPkosu(n,x))
#print(atusa)
#print(Pkosu)

Submission status: Wrong Answer

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

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

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

ans = 0
left = 0
mid = int(b[-1] / 2)
right = b[-1] - 1
i = len(b) - 1
while i > 0:
    if mid + 1 == x:
        ans += a[i - 1] + 1
        break
    elif mid < x:
        ans += a[i - 1] + 1
        left = mid + 1
        mid = mid + int((right - mid) / 2)
        right = right - 1
    else:
        right = mid - 1
        mid = mid - int((mid - left) / 2)
        left = left + 1
    i = i - 1

print(ans)

Submission status: Wrong Answer

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

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

if b[-1] == x:
    exit()

ans = 0
left = 0
mid = int(b[-1] / 2)
right = b[-1] - 1
i = len(b) - 1
while i > 0:
    if mid + 1 == x:
        ans += a[i - 1] + 1
        break
    elif mid < x:
        ans += a[i - 1] + 1
        left = mid + 1
        mid = mid + int((right - mid) / 2)
        right = right - 1
    else:
        right = mid - 1
        mid = mid - int((mid - left) / 2)
        left = left + 1
    i = i - 1

print(ans)

Submission status: Wrong Answer

Solution code:
def do(level,x):
    if x<=1:
        return 0
    elif x>=j[level]:
        return k[level]
    res=0
    x-=1
    if x>=j[level-1]+1:
        x-=j[level-1]+1
        res+=k[level-1]+1
    return res+do(level-1,x)

n,x=map(int,input().split())
j=[1]+[0]*50
k=[1]+[0]*50
for i in range(1,n+1):
    j[i]=j[i-1]*2+3
    k[i]=k[i-1]*2+1
res=0
print(do(n,x))

Submission status: Wrong Answer

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

c = [1, 1]
t = [c]
for i in range(N):
    c = [c[0] * 2 + 3, c[1] * 2 + 1]
    t.append(c)

def f(cur, n, k):
    if k <= 0: return cur
    u = t[n-1]
    m = u[0] + 2
    if m == k:
        return cur + 1 + u[1]
    elif k == 1:
        return cur
    elif k == t[n][0]:
        return cur + t[n][1]
    elif k > m:
        return f(cur + 1 + u[1], n - 1, k - u[0] - 2)
    elif m > k:
        return f(cur, n - 1, k - 1)

print(f(0, N, K))

Submission status: Wrong Answer

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

c = [1, 1]
t = [c]
for i in range(N):
    c = [c[0] * 2 + 3, c[1] * 2 + 1]
    t.append(c)

def f(cur, n, k):
    if k <= 0: return cur
    u = t[n-1]
    m = u[0] + 2
    if m == k:
        return cur + 1 + u[1]
    elif k > m:
        return f(cur + 1 + u[1], n - 1, k - u[0] - 2)
    elif m > k:
        return f(cur, n - 1, k - 1)

print(f(0, N, K))

Submission status: Wrong Answer

Solution code:
import math
N,X = list(map(int, input().split()))
cnt = 0
for i in range(N, 0, -1):
  t = math.pow(2, i + 1) - 2
  if X > t:
    cnt += t / 2
    X -= t
    if X > 1:
      cnt += 1
      X -= 1
    elif X == 1:
      cnt += 1
      break
    else:
      break
  else:
    if X > 1:
      X -= 1
    else:
      break
print(int(cnt))

Submission status: Wrong Answer

Solution code:
import math
n, x = list(map(int, input().split()))
def make_burger(level):
    if level == 0:
        return 0, 1
    lower, order = make_burger(level-1)
    burger = (1 << (order*2 + 2)) + (lower << (order + 2)) + (0 << (order + 1)) + (lower << 1) + 1
    return burger, math.ceil(math.log2(burger))

print(bin(make_burger(n)[0] & (2**x-1)).count("0"))

Submission status: Wrong Answer

Solution code:

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

p, a = [1], [1]

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

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

print(f(n,x))

Submission status: Wrong Answer

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

a, p = [1], [1]
for i in range(n):
    a.append(a[i]*2+3)
    p.append(a[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())

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

print(n,x)

Submission status: Wrong Answer

Solution code:
N,X = map(int,input().split())
if N == 0:
    print(1)
    exit()
# a:バンの数  b:パティの数
a,b = [1],[1]
for i in range(N):
    a.append(2*a[i] + 3)
    b.append(2*b[i] + 1)
def f(N,X):
    if X == 1:
        return 0
    elif 1 < X <= a[N-1] + 1:
        return f(N-1,X-1)
    elif X == a[N-1] + 2:
        return b[N-1] + 1
    elif a[N-1] + 2 < X <= 2*a[N-1] + 2:
        return b[N-1] + 1 + f(N-1,X-(a[N-1]+2))
    elif X == 2*a[N-1] + 3:
        return 2*b[N-1] + 1
ans = f(N,X)
print(ans)

Submission status: Wrong Answer

Solution code:
def high(n):
    if n==0:
        return 1
    else:
        return 2*(high(n-1)+1)+1
        
def rop(a,x):
    global ans
    while a>x:
        a=(a-3)//2
    b=a+1
    ans+=b//2
    if x<=0:
        return ans
    elif b==x:
        return ans
    elif b==x-1:
        ans+=1
        return ans
    else:
        ans+=1
        return rop(a,x-b-1)
        
n,x=map(int,input().split())
a=high(n)
ans=0
rop(a,x)
print(ans)

Submission status: Wrong Answer

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

def simple(l):
    if not l:
        return "P"
    mid = simple(l - 1)
    return "B{}P{}B".format(mid, mid)

def length(l):
    return -2 + (1 - 2**(l + 2)) // (1 - 2)


def plen(l):
    return (1 - 2**(l + 1)) // (1 - 2)


def blen(l):
    return -1 + (1 - 2**(l + 1)) // (1 - 2)

# -- all length ---
# *2+3
# 1, 5, 13, 29,  61
#  4  8   16   32
# +1 -3

# --- B length ---
# 0, 2, 6, 14, 30
#  2  4  8   16
# -1

# --- P length ---
# 1, 3, 7, 15, 31
#  2  4  8   16
# +1 -1


# n = 50
# print(length(n))
# n = 4
# k = 23

lenmap = [length(x) for x in range(51)]
plenmap = [plen(x) for x in range(51)]
blenmap = [blen(x) for x in range(51)]

def check(x, left, center, right):
    if x < center:
        if x == left:
            return -2
        else:
            return -1
    elif x > center:
        if x == right:
            return 2
        else:
            return 1
    else:
        return 0

# s = simple(n)
# print(s[:k], s[k:])
# print(" - - - - - ")

left = 1
right = lenmap[n] - 1
center = (left + right) // 2
result = 0
depth = n - 1
# tmp = s
for i in range(50):
    # print(left, center, right)
    # print(s[:center], s[center], s[center + 1:])
    # tmp = s[left : right]
    # print(tmp[:len(tmp) // 2], tmp[len(tmp) // 2], tmp[len(tmp) // 2 + 1:])

    pos = check(k, left, center, right)
    if pos in [-2, 0, 2]:
        if pos == -2:
            pass
        elif pos == 2:
            result += plenmap[depth + 1]
        else:
            result += plenmap[depth]
        break
    if pos == -1:
        left += 1
        right = center - 1
        center = (left + right) // 2
        # print("left")
    else:
        right -= 1
        left = center + 2
        center = (left + right) // 2
        result += plenmap[depth] + 1
    #     print("right", result, plenmap[depth] + 1)
    # print()
    depth -= 1
print(result)

Submission status: Wrong Answer

Solution code:
N,X = map(int,input().split())
# a:バンの数  b:パティの数
a,b = [1],[1]
for i in range(N):
    a.append(2*a[i] + 3)
    b.append(2*b[i] + 1)
def f(N,X):
    if X == 1:
        return 0
    elif 1 < X <= a[N-1] + 1:
        return f(N-1,X-1)
    elif X == a[N-1] + 2:
        return b[N-1] + 1
    elif a[N-1] + 2 < X <= 2*a[N-1] + 2:
        return b[N-1] + 1 + f(N-1,X-(a[N-1]+2))
    elif X == 2*a[N-1] + 3:
        return 2*b[N-1] + 1
ans = f(N,X)
print(ans)

Submission status: Wrong Answer

Solution code:
def feed_runrun(answer, burger_dimension, appetite):
    if appetite <= 0:
        return answer

    burger_size = 2 ** (burger_dimension + 2) - 3
    # 食べきれないなら小さくして試す
    if appetite < burger_size:
        return feed_runrun(answer, burger_dimension - 1, appetite - 1)

    amount_of_p = 2 ** (burger_dimension + 1) - 1
    if appetite == burger_size + 1:
        return answer + amount_of_p + 1
    return feed_runrun(answer + amount_of_p + 1, burger_dimension, appetite - burger_size - 1)


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

Submission status: Wrong Answer

Solution code:
def feed_runrun(answer, burger_dimension, appetite):
    if appetite <= 0:
        return answer

    burger_size = 2 ** (burger_dimension + 2) - 3
    # 食べきれない
    if appetite < burger_size:
        return feed_runrun(answer, burger_dimension - 1, appetite - 1)
    # 食べきれるので, 食べる
    amount_of_p = 2 ** (burger_dimension + 1) - 1
    return feed_runrun(answer + amount_of_p + 1, burger_dimension, appetite - burger_size - 1)


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

Submission status: Wrong Answer

Solution code:
def feed_runrun(answer, burger_dimension, appetite):
    if appetite >= 0:
        return answer

    burger_size = 2 ** (burger_dimension + 2) - 3
    # 食べきれない
    if appetite < burger_size:
        return feed_runrun(answer, burger_dimension - 1, appetite - 1)
    # 食べきれるので, 食べる
    amount_of_p = 2 ** (burger_dimension + 1) - 1
    return feed_runrun(answer + amount_of_p + 1, burger_dimension, appetite - burger_size - 1)


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

Submission status: Wrong Answer

Solution code:
(n, x) = list(map(int, input().split()))
num = 1
pate = 1
for i in range(n):
    num = num * 2 + 3
    pate = pate * 2 + 1
def culc(l, idx, num, pate):
    npate = (pate - 1) // 2
    nnum = (num - 3) // 2
    mid = (num + 1) // 2
    if l == 0:
        if idx == 1:
            return 1
        else:
            return 0
    elif mid == idx:
        return npate + 1
    elif mid < idx:
        return npate + 1 + culc(l - 1, idx - mid, nnum, npate)
    else:
        return culc(l - 1, idx - 1, nnum, npate)
print(culc(n, x, num, pate))

Submission status: Wrong Answer

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

sum_p = [1]
sum_dim = [1]

for i in range(n):
    sum_p.append(sum_p[i] * 2 + 1)
    sum_dim.append(sum_dim[i] * 2 + 3)


def cal(n, rem):
    if n == 0:
        return 1 if rem == 1 else 0
    elif rem <= 1 + sum_dim[n-1]:
        return cal(n - 1, rem - 1)
    else:
        return sum_p[n-1] + 1 + cal(n - 1, rem - 2 - sum_dim[n-1])


print(cal(n, x))

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
b = ""
def saiki(i):
    if i == 0:
        return 1
    else:
        return 3 + saiki(i-1) * 2

b = saiki(n)
res = 0
while True:
    if abs(b - x) <= 3:
        if x == 1:
            res += 0
            break
        if x == 2:
            res += 0
            break
        if x == 3:
            res += 1
            break
        if x == 4:
            res += 2
            break
        if x == 5:
            res += 3
            break
        if x == 6:
            res += 3
            break
        if x == 7:
            res += 3
            break
    if b % 2 == 0:
        b -= 1
    if b / 2 < x:
        res += 2**n
        x -= (b+1) / 2
        x += 1
        b = (b+1) / 2
    elif b / 2 == x:
        res += 2**n
        break
    else:
        b = (b+1) / 2 + 1
    n -= 1

print(res)

Submission status: Wrong Answer

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

sum_p = [0 for i in range(n + 1)]
sum_dim = [0 for i in range(n + 1)]
sum_p[0] = 1
sum_dim[0] = 1

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


def cal(n, rem):
    if n == 0:
        return 1 if rem == 1 else 0
    elif rem <= 1 + sum_dim[n]:
        return cal(n - 1, rem - 1)
    else:
        return sum_p[n] + 1 + cal(n - 1, rem - 2 - sum_dim[n])


print(cal(n, x))

Submission status: Wrong Answer

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

sum_p = [0 for i in range(n + 1)]
sum_dim = [0 for i in range(n + 1)]
sum_p[0] = 1
sum_dim[0] = 1

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


def cal(n, rem):
    if n == 0:
        return 1 if rem == 1 else 0
    elif rem <= 1 + sum_dim[n - 1]:
        return cal(n - 1, rem - 1)
    else:
        return sum_p[n - 1] + 1 + cal(n - 1, rem - 2 - sum_dim[n - 1])


print(cal(n, x))

Submission status: Wrong Answer

Solution code:
N,X=map(int,input().split())
L=[0]*(N+1)
t=1
L[0]=t
for i in range(1,N+1):
    t=2*t+3
    L[i]=t
M=[0]*(N+1)
s=1
for i in range(1,N+1):
    s=2*s+1
    M[i]=s
a=X
ans=0
for i in range(N-1,0,-1):
    t=L[i]
    s=M[i]
    if a==1:
        break
    elif 2<=a<=t+1:
        a-=1
    elif a==t+2:
        ans+=s+1
        break
    elif t+3<=a<=2*t+2:
        ans+=s+1
        a=a-(t+2)
    elif a==2*t+3:
        ans+=2*s+1
        break
print(ans)

Submission status: Wrong Answer

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

a, p = [1], [1]

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

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

print(f(N, X))

Submission status: Wrong Answer

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

bagaAtsusas=[]
bagaAtsusasP=[]
def bagaAtsusa(number):
  if number==0:
    bagaAtsusas.append(1)
    return 1
  else:
    tmp=3+ bagaAtsusa(number-1)*2
    bagaAtsusas.append(tmp)
    return tmp

def bagaAtsusaP(number):
  if number==0:
    bagaAtsusasP.append(1)
    return 1
  else:
    tmp=1 + bagaAtsusaP(number-1)*2
    bagaAtsusasP.append(tmp)
    return tmp

#どのバーガーまであるのかを知りたい
def donoBaga(bagaLevel,fukasa,numList,ans):
  if(fukasa==1):
    numList[bagaLevel-1]=0
    #今までのを足せばわかる
    for i in range(bagaLevel-1,len(numList)):
      ans+=bagaAtsusasP[i]*numList[i]
    print(ans)
  elif(fukasa<bagaAtsusas[bagaLevel-1]+1):
    #つぎへ
    numList[bagaLevel-1]=0
    fukasa=fukasa-1
    donoBaga(bagaLevel-1,fukasa,numList,ans)
  elif (fukasa==bagaAtsusas[bagaLevel-1]+1):
    numList[bagaLevel-1]=1
    #今までのを足せばわかる
    for i in range(bagaLevel-1,len(numList)):
      ans+=bagaAtsusasP[i]*numList[i]
    print(ans)
  elif (fukasa==bagaAtsusas[bagaLevel-1]+2):
    numList[bagaLevel-1]=1
    #今までのを足せばわかる
    for i in range(bagaLevel-1,len(numList)):
      ans+=bagaAtsusasP[i]*numList[i]
    ans=ans+1
    print(ans)
  elif(fukasa<bagaAtsusas[bagaLevel-1]*2+2):
    #つぎへ
    numList[bagaLevel-1]=1
    fukasa=fukasa-(bagaAtsusas[bagaLevel-1]+2)
    ans=ans+1
    donoBaga(bagaLevel-1,fukasa,numList,ans)
  elif (fukasa==bagaAtsusas[bagaLevel-1]*2+2):
    numList[bagaLevel-1]=2
    #今までのを足せばわかる
    for i in range(bagaLevel-1,len(numList)):
      ans+=bagaAtsusasP[i]*numList[i]
    ans=ans+1
    print(ans)
  elif (fukasa==bagaAtsusas[bagaLevel-1]*2+3):
    numList[bagaLevel-1]=2
    #今までのを足せばわかる
    for i in range(bagaLevel-1,len(numList)):
      ans+=bagaAtsusasP[i]*numList[i]
    ans=ans+2
    print(ans)
    
bagaAtsusa(n)
bagaAtsusaP(n)
numList=[0]*n
ans=0
donoBaga(n,x,numList,ans)
#print(numList)
#print(bagaAtsusas)
#print(bagaAtsusasP)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python

from sys import stdin, stderr

DPL = [0] * 52
DPP = [0] * 52

def F(n, x):
   if x == 0:
      return 0
   if x >= 1 + DPL[n-1] + 1:
      return DPP[n-1] + 1 + F(n-1, x - (1 + DPL[n-1] + 1))
   else:
      return F(n-1, x-1)

def main():
   N, X = map(int, stdin.readline().split())

   DPL[0] = 1
   DPP[0] = 1
   for n in xrange(1, N+1):
      DPL[n] = 2*DPL[n-1] + 3
      DPP[n] = 2*DPP[n-1] + 1

   res = F(N, X)
   print(res)

   return 0

if __name__ == '__main__': main()

Submission status: Wrong Answer

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

totalp = [1]
totalb = [1]
for _ in range(1, N+1):
  totalp.append(totalp[-1]*2 + 1)
  totalb.append(totalp[-1]*2 + 3)

def burger(N, X):
  if N == 0:
    return 0 if X == 0 else 1
  elif X < totalb[N-1] + 1:
    return burger(N-1, X-1)
  else:
    return totalp[N-1] + burger(N-1, X-2-totalp[N-1])

print(burger(N, X))

Submission status: Wrong Answer

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

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

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

def solve(L, X):
    if X == 1:
        return 0
    if 1 < X <= 1 + a(L-1):
        return solve(L-1, X-1)
    if X == 2 + a(L-1):
        return p(L-1) + 1
    if 2 + a(L-1) < X <= 2 + 2 * a(L-1):
        return p(L-1) + 1 + solve(L-1, X-a(L-1)-2)
    if X == 3 + 2 * a(L-1):
        return 2 * p(L-1) + 1

print(solve(N, X))

Submission status: Wrong Answer

Solution code:
N, X = map(int, input().split())
L2 = [1]
j = 1
for i in range(N+2):
    j *= 2
    L2.append(j)
Y = 0
for i in range(N):
    if L2[N+1-i] - 1 == X:
        Y += L2[N-i]
        print(Y)
        break
    elif L2[N+2-i] - 3 == X:
        Y += L2[N+1-i] - 1
        print(Y)
        break
    elif L2[N+1-i] - 1 < X:
        Y += L2[N-i]
        X -= L2[N+1-i] - 1
    else:
        X -= 1
else:
    print(Y)

Submission status: Wrong Answer

Solution code:
def waru(n_, x_):
    count = 0
    z = all[n_]
    while z > x_:
        z = z // 2 + 1
        count += 1
    return z, count

def kazoe(n_, x_, ans):
    z, count = waru(n_, x_)
    ans += pate[max(n_ - count, 0)]
    if x_ >= z and n_ >= count:
        ans += 1
        if x_ > z:
            return kazoe(n_ - count, x_ - z, ans)
        return ans
    else:
        return ans


all = [1, 5, 13, 29, 61, 125, 253, 509, 1021, 2045, 4093, 8189, 16381, 32765, 65533, 131069, 262141, 524285, 1048573, 2097149, 4194301, 8388605, 16777213, 33554429, 67108861, 134217725, 268435453, 536870909, 1073741821, 2147483645, 4294967293, 8589934589, 17179869181, 34359738365, 68719476733, 137438953469, 274877906941, 549755813885, 1099511627773, 2199023255549, 4398046511101, 8796093022205, 17592186044413, 35184372088829, 70368744177661, 140737488355325, 281474976710653, 562949953421309, 1125899906842621, 2251799813685245, 4503599627370493]
pate = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535, 131071, 262143, 524287, 1048575, 2097151, 4194303, 8388607, 16777215, 33554431, 67108863, 134217727, 268435455, 536870911, 1073741823, 2147483647, 4294967295, 8589934591, 17179869183, 34359738367, 68719476735, 137438953471, 274877906943, 549755813887, 1099511627775, 2199023255551, 4398046511103, 8796093022207, 17592186044415, 35184372088831, 70368744177663, 140737488355327, 281474976710655, 562949953421311, 1125899906842623, 2251799813685247]

n, x = map(int, input().split())
if n >= x:
    print(0)
    exit()
print(kazoe(n, x, 0))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10000000)

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

num = [0] * (n + 1)
num_p = [0] * (n + 1)
num_h = [0] * (n + 1)
num[0] = 1
num_p[0] = 1

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

for i in range(n + 1):
    num_h[i] = num[i] // 2 + 1

# idx 番目までに含むPの数を返す
def func(idx, n):
    if idx == 1 and n == 1:
        return 0
    if idx <= n or n < 1:
        return 0

    if idx == num_h[n]:
        ret = num_p[n - 1] + 1

    elif idx > num_h[n]:
        ret = num_p[n] - func(num[n] - idx - 1, n - 1)

    elif idx < num_h[n]:
        ret = func(idx - 1, n - 1)

    return ret

print(func(x, n))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(1000000)
N,X = map(int,input().split())
def n_barg_hight(n):
	if(n == 0):
		return 1

	L1barg_height = n_barg_hight(n-1)
	Lbarg_height = 1 + L1barg_height + 1 + L1barg_height + 1
	return Lbarg_height

def n_barg_pat(n):
	if(n == 0):
		return 1
	L1barg_pat = n_barg_pat(n-1)
	Lbarg_pat = 1 + L1barg_pat*2
	return Lbarg_pat


def answer(N,X):

	if(X == 1):
		return 0
	
	elif(X == n_barg_hight(N)):
		return n_barg_pat(N)

	elif(X == n_barg_hight(N)//2 + 1):
		return n_barg_pat(N-1)+1

	elif(X <= n_barg_hight(N)//2):
		return answer(N-1,X-1)

	elif(X > n_barg_hight(N)//2 + 1):
		Lbarg = n_barg_pat(N-1) + answer(N-1,X-n_barg_hight(N-1)-2) +1
		return Lbarg


print(answer(N,X))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(1000000)
N,X = map(int,input().split())
def n_barg_hight(n):
	if(n == 0):
		return 1

	L1barg_height = n_barg_hight(n-1)
	Lbarg_height = 1 + L1barg_height + 1 + L1barg_height + 1
	return Lbarg_height

def n_barg_pat(n):
	if(n == 0):
		return 1
	L1barg_pat = n_barg_pat(n-1)
	Lbarg_pat = 1 + L1barg_pat*2
	return Lbarg_pat


def answer(N,X):
	print(N,X)
	if(X == 1):
		return 0
	
	elif(X == n_barg_hight(N)):
		return n_barg_pat(N)

	elif(X == n_barg_hight(N)//2 + 1):
		return n_barg_pat(N-1)+1

	elif(X <= n_barg_hight(N)//2):
		return answer(N-1,X-1)

	elif(X > n_barg_hight(N)//2 + 1):
		Lbarg = n_barg_pat(N-1) + answer(N-1,X-n_barg_hight(N-1)-2) +1
		return Lbarg


print(answer(N,X))