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

i = 1
ans = 0
f = True
span = n

while i < x:
    if f:
        span -= 1
    else:
        span += 1

    if span == 1:
        f = False
        ans += 1

    i += span
    ans += 1

print(ans)

Submission status: Wrong Answer

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

def func(l=N, x=X):
	if (l == 0):
		return x
	if (x <= 1):
		return 0
	if (x < fcnt[l-1]+2):
		return func(l - 1, x - 1)
	elif (x == fcnt[l - 1] + 2):
		return pcnt[l-1]+1
	else:
		return pcnt[l-1]+1+func(l-1, x-fcnt[l-1]-2)

print(func())

Submission status: Wrong Answer

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

def func(l=N, x=X):
	if (l == 0):
		return x
	if (x == 1):
		return 0
	if (x < fcnt[l-1]+2):
		return func(l - 1, x - 1)
	elif (x == fcnt[l - 1] + 2):
		return pcnt[l-1]+1
	else:
		return pcnt[l-1]+1+func(l-1, x-fcnt[l-1]-2)

print(func())

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):
    result = 0
    for i in range(n, -1, -1):
        rem -= 1
        if rem >= sum_dim[i - 1]:
            result += sum_p[i - 1]
            rem -= sum_dim[i - 1]
        else:
            # rem = rem - (i -2)
            if rem >= 0:
                result += cal(i - 1, rem)
                break
            else:
                break
        if rem >= 1:
            result += 1
            rem -= 1
    return result


print(cal(n, x))

Submission status: Wrong Answer

Solution code:
#coding:utf-8
ls_len = [1]
ls_p = [1]
for i in range(50):
    ls_len.append(2*ls_len[-1]+3)
    ls_p.append(1+2*ls_p[-1])
n,x = map(int,input().split())

def calc_p(level,x):
    if level == 0:
        return 1
    elif x == ls_len[level]-1:
        return ls_p[level]
    elif x == 0:
        return 0
    elif x == (ls_len[level]-1)/2:
        return ls_p[level-1]+1
    elif x < (ls_len[level]-1)/2:
        return calc_p(level-1,x-1)
    else:
        return calc_p(level-1,x-2-ls_len[level-1])+ls_p[level-1]+1
print (calc_p(n,x))

Submission status: Wrong Answer

Solution code:
def PAndB(n):
    return (2 ** (n + 2)) - 3


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


def count(N, X):
    if N == 0:
        return 1
    elif X <= N:
        return 0
    elif X >= PAndB(N) - (N - 1):
        return allPatty(N)
    elif X == PAndB(N - 1) + 2:
        print('center')
        return allPatty(N - 1) + 1
    elif X <= PAndB(N - 1) + 1:
        return count(N - 1, X - 1)
    else:
        return allPatty(N - 1) + 1 + count(N - 1, X - (PAndB(N - 1) + 2))


def main():
    N, X = map(int, input().split())
    print(count(N, X))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
m = input()
n = int(m.split()[0])
x = int(m.split()[1])
c = 0
l = 2**(n+2)-3
p = 2**(n+1)-1
while l > 0:
    h = 2**(n+1)-1
    if x == h:
        c += 2**n
        break
    elif x > h:
        c += 2**n
        x -= 2**(n+1)-1
    l = (l+3)/2-3
    p = (p+1)/2-1
    n -= 1
    
print(c)

Submission status: Wrong Answer

Solution code:
n,x = input().split()
n = int(n)
x = int(x)
memo = [[0,0] for i in range(n+1)]
memo[0][0] = 1
memo[0][1] = 1
for i in range(n):
    memo[i+1][0] = 2 * memo[i][0] + 1
    memo[i+1][1] = 2 * memo[i][1] + 3
sum = 0
while (n >= 0 and x >= 0):
    if x <= 1 + memo[n-1][1]:
        n -= 1
        x -= 1
    elif x == 2 + memo[n-1][1]:
        sum += (memo[n-1][0] + 1)
        break
    else:
        x = x - memo[n-1][1] - 2
        n -= 1
        sum += (memo[n][0] + 1)
print(sum)

Submission status: Wrong Answer

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

pl = [1]
pa = [1]

for i in range(n):
    tmpp = pl[-1]
    tmpa = pa[-1]
    pl.append(tmpp*2+1)
    pa.append(tmpa*2+3)

def largest(n,x):
    if x <= 0:
        return 0
    else:
        if n <= 0:
            return x
        else:
            if x > pa[n]:
                return pl[n] + 1 + largest(n-1, x-2-pa[n])
            elif x == pa[n]:
                return pl[n]
            else:
                return largest(n-1,x-1)

print(largest(n,x))

Submission status: Wrong Answer

Solution code:
lens=[1 for _ in range(51)]
nump=[1 for _ in range(51)]
for i in range(50):
    lens[i+1]=2*lens[i]+3
    nump[i+1]=2*nump[i]+1
def level(n):
    return max(lvl for lvl,ln in enumerate(lens) if ln<=n)

def calc():
    table={}
    def _calc(l,x):
        if x==0:
            return 0
        if (l,x) in table:
            return table[(l,x)]
        if x<=lens[l-1]:
            res=_calc(l-1,x-1)
        elif x==lens[l-1]+1:
            res=nump[l-1]
        elif x==lens[l-1]+2:
            res=nump[l-1]+1
        else:
            res=nump[l-1]+1+_calc(l-1,x-lens[l-1]-2)
        table[(l,x)]=res
        return res
    return _calc
whole=calc()
print(whole(*map(int,input().split())))

Submission status: Wrong Answer

Solution code:
s = []
p = []


def eat(x, i):
    if x <= 0:
        return 0
    elif x - i + 1 >= s[i]:
        return p[i]
    elif x >= s[i - 1] + 1:
        r = p[i - 1] + 1 if x >= s[i - 1] + 2 else 0
        return r + eat(x - s[i - 1] - 2, i - 1)
    else:
        return eat(x - 1, i - 1)


def solve():
    N, X = map(int, input().split())
    s.append(1)
    p.append(1)
    for i in range(N):
        s.append(2 * s[i] + 3)
        p.append(2 * p[i] + 1)
    print(eat(X, N))


solve()

Submission status: Wrong Answer

Solution code:
n,x = map(int,input().split())
l1='BPPPB'
for i in range(n-1):
    l2 = 'B'+l1+'P'
    l1 = l2
y = l1[:x].count('P')
print(y)

Submission status: Wrong Answer

Solution code:
s = []
p = []


def eat(x, i):
    if x <= 1:
        return 0
    elif x - i + 1 >= s[i]:
        return p[i]
    elif x >= s[i - 1] + 1:
        r = p[i - 1] + 1 if x >= s[i - 1] + 2 else 0
        return r + eat(x - s[i - 1] - 2, i - 1)
    else:
        return eat(x - 1, i - 1)


def solve():
    N, X = map(int, input().split())
    s.append(1)
    p.append(1)
    for i in range(N):
        s.append(2 * s[i] + 3)
        p.append(2 * p[i] + 1)
    print(eat(X, N))


solve()

Submission status: Wrong Answer

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

def func(l=N, x=X):
	if (x == 0):
		return 0
	if (l == 0):
		return x
	if (x < fcnt[l-1]+2):
		return func(l-1, x-1)
	else:
		return pcnt[l-1]+1+func(l-1, x-fcnt[l-1]-2)

print(func())

Submission status: Wrong Answer

Solution code:
N,X=map(int,input().split())
bg=[1]
l=[1]
for _ in range(N):
    bg.append(bg[-1]*2+1)
    l.append(l[-1]*2+3)

def eat(n,x):#レベル,食べる層の数
    if x<=1: return 0
    #if x==l[n-1]+1: return bg[n-1]
    if x==l[n]: return bg[n]
    if x<=l[n-1]+1: return eat(n-1,x-1)
    return bg[n-1]+1+eat(n-1,x-l[n-1]-2)
print(eat(N,X))

Submission status: Wrong Answer

Solution code:
def abc115_d():
    n, x = map(int, input().split())
    l = [1] * 51
    p = [1] * 51
    for i in range(50):
        l[i + 1] = 2 * l[i] + 3
        p[i + 1] = p[i] * 2 + 1

    ans = 0
    while n:
        if x > (l[n] // 2):
            ans += p[n - 1] + 1
            x -= (l[n - 1] + 2)
            n -= 1
        else:
            x -= 1
            n -= 1
    if x == 1:
        ans += 1

    print(ans)


abc115_d()

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):
    if l == 0:
        return 0
    elif (num + 1) // 2 == idx:
        return (pate - 1) // 2 + 1
    elif (num + 1) // 2 < idx:
        return (pate - 1) // 2 + 1 + culc(l - 1, idx - (num + 1) // 2, (num - 3) // 2, (pate - 1) // 2)
    else:
        return culc(l - 1, idx - 1, (num - 3) // 2, (pate - 1) // 2)
print(culc(n, x, num, pate))

Submission status: Wrong Answer

Solution code:
def bu(n):
  if n == 0:
    return 'p'
  else:
    return 'b' + bu(n-1) + 'p' + bu(n-1) + 'b'



  
from collections import Counter

n, x = map(int, input().split())
#li = list(bu(n))
#print(li)
"""
count = 0
for i in range(x):
  if bu(n)[i] == 'p':
    count += 1
"""
count = Counter(bu(n))
print(count['p'])

Submission status: Wrong Answer

Solution code:
n,x = input().split()
n = int(n)
x = int(x)
memo = [[0,0] for i in range(n)]
memo[0][0] = 1
memo[0][1] = 1
for i in range(n-1):
    memo[i+1][0] = 2 * memo[i][0] + 1
    memo[i+1][1] = 2 * memo[i][1] + 3
sum = 0
while (n > 0 and x > 0):
    if x <= 1 + memo[n-1][1]:
        n -= 1
        x -= 1
    elif x == 2 + memo[n-1][1]:
        sum += (memo[n-1][0] + 1)
        break
    else:
        x = x - memo[n-1][1] - 2
        n -= 1
        sum += (memo[n][0] + 1)
print(sum)

Submission status: Wrong Answer

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

burger = [1]
pati = [1]
for i in range(1,52):
    burger.append(burger[i-1]*2+3)
    pati.append(pati[i-1]*2+1)
    
def calc(l, eat):
    if eat == 1:
        return 0
    elif eat <= burger[l-1]+1:
        return calc(l-1, eat-1)
    elif eat == burger[l-1]+2:
        return pati[l-1] + 1
    elif eat <= (burger[l-1]+1)*2:
        return calc(l-1, eat-(2+burger[l-1])) + pati[l-1]
    elif eat == (burger[l-1]*2) + 3:
        return (2*pati[l-1]) + 1

print(calc(N, X))

Submission status: Wrong Answer

Solution code:
def abc115_d():
    n, x = map(int, input().split())
    l = [1] * 51
    p = [1] * 51
    for i in range(50):
        l[i + 1] = 2 * l[i] + 3
        p[i + 1] = p[i] * 2 + 1

    ans = 0
    while n > 1:
        if x > (l[n] // 2):
            ans += p[n - 1] + 1
            x -= (l[n - 1] + 2)
            n -= 1
        else:
            x -= 1
            n -= 1

    print(ans)


abc115_d()

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
bli = []
pli = []
z = 2 ** (n + 2) - 3
count = 0
for i in range(n + 1):
    y = 2 ** (i + 2) - 3
    bli.append(y // 2 + 1)
    pli.append(y // 2)
for i in range(n, -1, -1):
    if x > (2 ** (i + 2) - 3) // 2 + 1:
        count += bli[i - 1] + 1
        x -= (2 ** (i + 2) - 3) // 2
    elif x == (2 ** (i + 2) - 3) // 2 + 1:
        count += bli[i - 1] + 1
        break
    x -= 1
print(count)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(3000)

N,X = (int(i) for i in input().split(' '))

L = [1]
P = [1]
for i in range(N):
    L.append(2*L[i] + 3) # 総枚数
    P.append(2*P[i] + 1) #　パティ数

# X はなんレベルバーガ内か？
#print(L)
#print(P)
# X はレベルlv バーガのどこにいるのか？
def find_level(lv, x):
    
#    print(lv, x)
    if lv == 0:
        return 1
    
    midlv = L[lv-1] + 2
    
    # 最上層
    if x == L[lv]:
#        print('最上層')
        ret = P[lv]
    # 最上層から真ん中
    if x < L[lv] and x > midlv:
#        print('最上層〜真ん中')
        ret = find_level(lv-1,x - midlv) + 1 + P[lv-1]
    # ちょうど真ん中
    elif x == midlv:
#        print('真ん中')
        ret = 1 + P[lv-1] 
    # 真ん中〜最下層
    elif x < midlv and x > 1:
#        print('真ん中〜最下層')
        ret = find_level(lv-1, x - 1)
    # 最下層
    else:
        ret = 0
        
    return(ret)

r = find_level(N, X)
print(r)

Submission status: Wrong Answer

Solution code:
N,X=map(int,input().split())
bg=[1]
l=[1]
for _ in range(N):
    bg.append(bg[-1]*2+1)
    l.append(l[-1]*2+3)

def eat(n,x):#レベル,食べる層の数
    if x<=1: return 0
    if x==l[n-1]+1: return bg[n-1]
    if x==l[n]: return bg[n]
    if x<=l[n-1]: return eat(n-1,x-1)
    return bg[n-1]+1+eat(n-1,x-l[n-1]-2)
print(eat(N,X))

Submission status: Wrong Answer

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

pl = [1]
pa = [1]

for i in range(n):
    tmpp = pl[-1]
    tmpa = pa[-1]
    pl.append(tmpp*2+1)
    pa.append(tmpa*2+3)

def largest(n,x):
    if x <= 0:
        return 0
    else:
        if n == 0:
            return x
        else:
            if x > pa[n]:
                return pl[n] + 1 + largest(n-1, x-2-pa[n])
            elif x == pa[n]:
                return pl[n]
            else:
                return largest(n-1,x-1)

print(largest(n,x))

Submission status: Wrong Answer

Solution code:
import numpy as np

n,x=[int(i) for i in input().split()]
burger="BAPAB"
for i in range(n-1):
    if(x<len(burger)):
        burger=burger[0:x]
    burger=burger.replace("A","BAPAB")
ans=0
burger=burger.replace("A","P")
print(burger)

ans=burger[0:x].count("P")
print(ans)

Submission status: Wrong Answer

Solution code:
N,X = (int(i) for i in input().split(' '))

L = [1]
P = [1]
for i in range(N):
    L.append(2*L[i] + 3) # 総枚数
    P.append(2*P[i] + 1) #　パティ数

# X はなんレベルバーガ内か？
#print(L)
#print(P)
# X はレベルlv バーガのどこにいるのか？
def find_level(lv, x):
    
#    print(lv, x)
    if lv == 0:
        return 1
    
    midlv = L[lv-1] + 2
    
    # 最上層
    if x == L[lv]:
#        print('最上層')
        ret = P[lv]
    # 最上層から真ん中
    if x < L[lv] and x > midlv:
#        print('最上層〜真ん中')
        ret = find_level(lv-1,x - midlv) + 1 + P[lv-1]
    # ちょうど真ん中
    elif x == midlv:
#        print('真ん中')
        ret = 1 + P[lv-1] 
    # 真ん中〜最下層
    elif x < midlv and x > 1:
#        print('真ん中〜最下層')
        ret = find_level(lv-1, x - 1)
    # 最下層
    else:
        ret = 0
        
    return(ret)

r = find_level(N, X)
print(r)

Submission status: Wrong Answer

Solution code:
N,X=map(int,input().split())
bg=[1]
l=[1]
for _ in range(N):
    bg.append(bg[-1]*2+1)
    l.append(l[-1]*2+3)

def eat(n,x):#レベル,食べる層の数
    if x<=1: return 0
    if x<=l[n]//2: return eat(n-1,x-1)
    if x==l[n]: return bg[n]
    return bg[n-1]+1+eat(n-1,x-l[n-1]-2)
print(eat(N,X))

Submission status: Wrong Answer

Solution code:
def total(n):
    return 2**(n+2)-3

def left(total,x):
    if x > (total+1)//2:
        return x-(total+1)//2
    else:
        return x
def pati(n):
    return 2**(n+1)-1

n,x = map(int,input().split())
num = []
p = []
for i in range(n-1):
    num.append(total(i))
for i in range(n+1):
    p.append(pati(i))


one = ["B","P","P","P","B"]
num.reverse()
eat = [0 for i in range(n+1)]

ans = 0
for i in range(n-1):
    if x == total(n-i):
        eat[n-i] += 1
        x = 0
    elif x > (total(n-i)+1)//2:
        eat[n-i-1] += 1
        x = left(total(n-i),x)
        ans += 1
    elif x == (total(n-i)+1)//2:
        eat[n-i-1] += 1
        eat[0] += 1
        x = 0
    else:
        x -= 1

for i in range(len(eat)):
    ans += eat[i]*p[i]
if 2<=x<=4:
    ans += x-1
print(ans)

Submission status: Wrong Answer

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

i = 0
ans = 0
f = True
span = n+1
while i < x:
    if span == 0:
        f = False
    if f:
        span -= 1
    else:
        span += 1
    i += span + 1
    ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
import pdb
import sys
sys.setrecursionlimit(10000)

def eat(n, x):
    ret = 0

    if x == 0:
        return 0, x

    if n == 0:
        x -= 1
        return 1, x

    if allnum[n] <= x:
        x -= allnum[n]
        return pnum[n], x
        
    
    x -= 1 # eat bread
    if x == 0:
        return 0, x

    # eat n-1 beager
    tmp, x = eat(n - 1, x)
    ret += tmp
    if x == 0:
        return ret, x

    # eat patty
    x -= 1
    ret += 1
    if x == 0:
        return ret, x

    # eat n-1 beager
    tmp, x = eat(n - 1, x)
    ret += tmp
    if x == 0:
        return ret, x

    x -= 1 # eat bread
        
    return ret, x


def main():
    tmp = input().split()
    n = int(tmp[0])
    x = int(tmp[1])
    global pnum
    global allnum
    pnum = [1]
    allnum = [1]
    for i  in range(1, 52):
        pnum.append(pnum[i-1] * 2 + 1)
        allnum.append(allnum[i-1] * 2 + 3)
    print(len(pnum))
    print(len(allnum))
    
    ans, tmp = eat(n, x)

    print("%d" % ans)

        
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

num_of_all = {0:1}
for i in range(1, n):
    num_of_all[i] = 2 * num_of_all[i-1] + 3

num_of_P = {0:1}
for i in range(1, n):
    num_of_P[i] = 2 * num_of_P[i-1] + 1
#pprint.pprint(num_of_all)
#pprint.pprint(num_of_P)

def num_of_P_from_bottom(level, x):
    if level == 0:
        return 1

    prev_level_all = num_of_all[level-1]
    prev_level_P   = num_of_P[level-1]
    ret = 0

    if x <= 1:
        return 0
    elif x < (2 + prev_level_all):
        if x == 2 + prev_level_all:
            ret += 1
        ret += num_of_P_from_bottom(level-1, x-1)
    else:
        ret += 1 + prev_level_P
        ret += num_of_P_from_bottom(level-1, x - (prev_level_all + 2))
    return ret

tmp = num_of_P_from_bottom(n, x)
print(tmp)

Submission status: Wrong Answer

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

pl = [1]
pa = [1]

for i in range(n):
    tmpp = pl[-1]
    tmpa = pa[-1]
    pl.append(tmpp*2+1)
    pa.append(tmpa*2+3)

def largest(n,x):
    if x <= 0:
        return 0
    else:
        if n == 0:
            return 1
        else:
            if x > pa[n]:
                return pl[n] + 1 + largest(n-1, x-2-pa[n])
            elif x == pa[n]:
                return pl[n]
            else:
                return largest(n-1,x-1)

print(largest(n,x))

Submission status: Wrong Answer

Solution code:
# encoding: utf-8
N, X = map(int, input().split())

L_child = 2 ** ((N - 1) + 2) - 3
P_child = 2 ** ((N - 1) + 1) - 1

def count(depth, pos):
    L_child = 2 ** ((depth - 1) + 2) - 3
    P_child = 2 ** ((depth - 1) + 1) - 1
    if depth == 0: return 1 # oh...
    # solved
    if pos == 0: return 0
    elif pos < L_child + 1: return count(depth - 1, pos - 1)
    elif pos == L_child + 1: return P_child + 1
    elif L_child + 1 < pos < 2 * (L_child + 1):
        return P_child + 1 + count(depth - 1, pos - (L_child + 2))
    else: return 2 * P_child + 1

print(count(N, X))

Submission status: Wrong Answer

Solution code:
N,X=[int(_) for _ in input().split()]
def countP(n):
    if n == 0:
        return 1
    elif n == 1:
        return 3
    else:
        return 1 + countP(n-1) * 2

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

def countPinBP(n,x):
    if n == 0:
        if x == 1:
            return 0
        else:
            return 1
    elif n == 1:
        if x == 1:
            return 0
        elif x < 5:
            return x - 1
        else:
            return 3
    else:
        iH = countBP(n) // 2
        if x <= iH:
            return countPinBP(n-1,x-1)
        elif x == iH + 1:
            return countP(n-1) + 1
        else:
            return countP(n-1) + 1 + countPinBP(n - 1, x - iH - 1)
print(countPinBP(N,X))

Submission status: Wrong Answer

Solution code:
memo = {}


def solve(N, X):
    if (N, X) not in memo:
        l = (pow(2, N + 2) - 3)
        l2 = l // 2
        if N == 0:
            return 1
        elif X == 1 or X == 0:
            return 0
        elif X == l2:
            memo[(N, X)] = solve(N - 1, l2 - 1) + 1
        elif X < l2:
            memo[(N, X)] = solve(N - 1, X - 1)
        elif X > l2:
            left = solve(N - 1, l2 - 1)
            right = solve(N - 1, X - l2 - 1)
            memo[(N, X)] = left + 1 + right
    return memo[(N, X)]


if __name__ == "__main__":
    N, X = tuple(map(int, input().split(" ")))
    print(solve(N, X))

Submission status: Wrong Answer

Solution code:
nx = list(map(int, input().split()))
n = nx[0]
x = nx[1]
p = 0
for i in range(n):
    l_thick = 2 ** (n - i + 1) - 3
    if x == 1:
        break
    elif x <= l_thick:
        x = x - 1
    elif x == l_thick + 1 :
        p += 2 ** (n - i) - 1
        break
    elif x <= l_thick * 2 + 1:
        x = x - l_thick - 2
        p += 2 ** (n - i)
    else:
        p += 2 * (2 ** (n - i) - 1) + 1
print(p)

Submission status: Wrong Answer

Solution code:
# encoding: utf-8
N, X = map(int, input().split())

L_child = 2 ** ((N - 1) + 2) - 3
P_child = 2 ** ((N - 1) + 1) - 1

def count(depth, pos):
    L_child = 2 ** ((depth - 1) + 2) - 3
    P_child = 2 ** ((depth - 1) + 1) - 1
    if depth == 0: return 0
    # solved
    if pos == 0: return 0
    elif pos < L_child + 1: return count(depth - 1, pos - 1)
    elif pos == L_child + 1: return P_child + 1
    elif L_child + 1 < pos < 2 * (L_child + 1):
        return P_child + 1 + count(depth - 1, pos - (L_child + 2))
    else: return 2 * P_child + 1

print(count(N, X))

Submission status: Wrong Answer

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

def f(n):
    return 4 * pow(2, n) - 3
def g(n):
    return pow(2, n+1) - 1

def ss2(k, n):
    nn = f(n)
    cc = (nn//2) + 1
    if k == 1:
        return 1
    if k >= nn:
        return g(n) 
    elif k == cc:
        return g(n-1) + 1  
    elif k > cc:
        return g(n-1) + 1 + ss2(k-cc, n-1)
    elif k < cc:
        return ss2(k-1, n-1)

print(ss2(X, N))

Submission status: Wrong Answer

Solution code:
def p_num(n,x):
    #print(n,x)

    m = 2**(n+1)-1
    #print(m)
    if x==1:
        return 0
    elif x==2*m-1:
        return m

    if n==0:
        return 1
    else:
        if x < m:
            #print("::1")
            return p_num(n-1, x-1)
        elif x > m:
            #print("::2")
            return (m-1)//2 + 1 + p_num(n-1, x-(2**(n+1)-1))
        else:
            #print("::3")
            return (m-1)//2 + 1


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

print(p_num(n,x))

Submission status: Wrong Answer

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

l = 1

c = [1]
d = [1]

for i in range(50):
	c.append(2*c[-1]+3)
	d.append(2*d[-1]+1)
k = 0
while True:
	if a == 0:
		k += 1
		break
	elif b==1:
		break
	elif c[a] // 2 == b:
		k += d[a-1]
		break
	elif c[a] // 2 > b:
		a -= 1
		b -= 1
	elif c[a] // 2 + 1 == b:
		k += 1 + d[a-1]
		break
	elif c[a] == b:
		k = d[a]
		break
	else:
		a -= 1
		k += d[a]+1
		b -= c[a] + 2


print(k)

Submission status: Wrong Answer

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

pl = [1]
pa = [1]

for i in range(n):
    tmpp = pl[-1]
    tmpa = pa[-1]
    pl.append(tmpp*2+1)
    pa.append(tmpa*2+3)

def largest(n,x):
    if x <= 0:
        return 0
    else:
        if x > pa[n]:
            return pl[n] + 1 + largest(n-1, x-2-pa[n])
        elif x == pa[n]:
            return pl[n]
        else:
            return largest(n-1,x-1)

print(largest(n,x))

Submission status: Wrong Answer

Solution code:
memo = {}


def solve(N, X):
    if (N, X) not in memo:
        l = (pow(2, N + 2) - 3)
        l2 = l // 2
        if N == 0:
            return 1
        elif X == 0:
            return 0
        elif X == l2:
            memo[(N, X)] = solve(N - 1, l2 - 1) + 1
        elif X < l2:
            memo[(N, X)] = solve(N - 1, X - 1)
        elif X > l2:
            left = solve(N - 1, l2 - 1)
            right = solve(N - 1, X - l2 - 1)
            memo[(N, X)] = left + 1 + right
    return memo[(N, X)]


if __name__ == "__main__":
    N, X = tuple(map(int, input().split(" ")))
    print(solve(N, X))

Submission status: Wrong Answer

Solution code:
nx = list(map(int, input().split()))
n = nx[0]
x = nx[1]
p = 0
for i in range(n):
    l_thick = 2 ** (n - i + 1) - 3
    if x <= l_thick:
        x = x - 1
    elif x == l_thick + 1 :
        p += 2 ** (n - i) - 1
        break
    else:
        x = x - l_thick - 2
        p += 2 ** (n - i)
print(p)

Submission status: Wrong Answer

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

totalb = [1]
for _ in range(1, N+1):
  totalb.append(totalb[-1]*2+3)
  
totalp=0
X -= 1
while X!=0:
  for x in totalb:
    if x > X:
      break
  tmp = totalb[totalb.index(x)-1]
  X -= tmp
  totalp += tmp // 2 + 1

print(totalp)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Dec  8 20:51:18 2018

@author: Owner
"""

import collections
import scipy.misc
import sys
import numpy as np
import math
from operator import itemgetter

def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   

def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []

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

x = [0]*N
x[:] = map(int, input().split())

P = [0]*M
Y = [0]*M
for m in range(M):
    P[m], Y[m] = map(int, input().split())
    
all(nstr.count(c) for c in '753')
"""

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

burger = 'P'
if N == 0:
    print(1)
    sys.exit()

"""
for n in range(N):
    burger = 'B' + burger + 'P' +burger +'B'
burger4eat = burger[0:X]
"""
burger4eat = (X//6)*4 
if X%6 == 1:
    pass
elif X%6 == 2:
    burger4eat += 1
elif X%6 == 3:
    burger4eat += 2
elif X%6 == 4:
    burger4eat += 3
elif X%6 == 5:
    pass

print(burger4eat)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from sys import stdin

def solve():
    n, x = map(int, stdin.readline().split())
    items = []
    items.append([1,1])
    for i in range(1,n+1):
        items.append([items[-1][0]*2+3, items[-1][1]*2+1])
    
    if x<=n:
        print(0)
        return
    
    ans = 0
    p = n
    while p and x:
        half = (items[p][0]+1)//2
        if x>=half:
            ans += items[p-1][1] + 1
            x -= half
        else:
            x -= 1
        p -= 1
    ans += x
    print(ans)

solve()

Submission status: Wrong Answer

Solution code:
def dfs(lft, rgt, x, L):
    if L == 0: return 0
    if x < lft: return 0
    mid = (lft + rgt) // 2
    ans = 0
    if mid - 1 <= x:
        ans += numPs[L - 1]
    else:
        ans += dfs(lft + 1, mid - 1, x, L - 1)
    if mid <= x:
        ans += 1
    if mid < x:
        ans += dfs(mid + 1, rgt - 1, x, L - 1)
    return ans

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

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

print(dfs(1, As[N], X, N))

Submission status: Wrong Answer

Solution code:
nx = list(map(int, input().split()))
n = nx[0]
x = nx[1]
p = 0
for i in range(n):
    l_thick = 2 ** (n - i + 1) - 3
    if x <= l_thick + 1:
        x = x - 1
    else:
        x = x - l_thick - 2
        p += 2 ** (n - i)
    if x == 0:
        break
print(p)

Submission status: Wrong Answer

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

l = 1

c = [1]
d = [1]

for i in range(50):
	c.append(2*c[-1]+3)
	d.append(2*d[-1]+1)
k = 0
while True:
	if b == 1 and a == 0:
		k += 1
		break
	elif b==1:
		break
	elif c[a] // 2 == b:
		k += d[a-1]
		break
	elif c[a] // 2 > b:
		a -= 1
		b -= 1
	elif c[a] // 2 + 1 == b:
		a -= 1
		k += 1 + d[a]
		break
	elif c[a] == b:
		k = d[a]
		break
	elif a == 0:
		k += 1
		break
	else:
		a -= 1
		k += d[a]+1
		b -= c[a] + 2


print(k)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from sys import stdin

def solve():
    n, x = map(int, stdin.readline().split())
    items = []
    items.append([1,1])
    for i in range(1,n+1):
        items.append([items[-1][0]*2+3, items[-1][1]*2+1])
    
    if x<=n:
        print(0)
        return
    
    ans = 0
    p = n
    while p and x:
        half = (items[p][0]+1)//2
        if x>=half:
            ans += items[p-1][1] + 1
            x -= half
        else:
            x -= 1
        p -= 1
    if ans==0:
        ans = 1
    print(ans)

solve()

Submission status: Wrong Answer

Solution code:
n,x = input().split()
n = int(n)
x = int(x)
memo = [[0,0] for i in range(n)]
memo[0][0] = 1
memo[0][1] = 1
for i in range(n-1):
    memo[i+1][0] = 2 * memo[i][0] + 1
    memo[i+1][1] = 2 * memo[i][1] + 3
sum = 0
while (n >= 0 and x >= 0):
    if x <= 1 + memo[n-1][1]:
        n -= 1
        x -= 1
    elif x == 2 + memo[n-1][1]:
        sum += (memo[n-1][0] + 1)
        break
    else:
        x = x - memo[n-1][1] - 2
        n -= 1
        sum += (memo[n][0] + 1)
print(sum)

Submission status: Wrong Answer

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

r = 3 + (n - 1) * 10
h = int((r + 1) / 2)
if h > x:
    a = x - 1
    ans = a // 5 * 3
    if a % 5 == 2:
        ans += 1
    elif a % 5 == 3:
        ans += 2
    elif a % 5 == 4:
        ans += 3
    elif a % 5 == 5:
        ans += 3
elif h == x:
    ans = (n - 1) * 3 + 1
else:
    ans = (n - 1) * 3 + 1
    a = x - h
    ans += a // 5 * 3
    if a % 5 == 2:
        ans += 1
    elif a % 5 == 3:
        ans += 2
    elif a % 5 == 4:
        ans += 3
    elif a % 5 == 5:
        ans += 3

print(ans)

Submission status: Wrong Answer

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

l = 1

c = [1]
d = [1]

for i in range(50):
	c.append(2*c[-1]+3)
	d.append(2*d[-1]+1)
k = 0
while True:
	if b == 1:
		break
	elif c[a] // 2 == b:
		k += d[a-1]
		break
	elif c[a] // 2 > b:
		a -= 1
		b -= 1
	elif c[a] // 2 + 1 == b:
		a -= 1
		k += 1 + d[a]
		break
	elif c[a] == b:
		k = d[a]
		break
	elif a == 0:
		k += 1
		break
	else:
		a -= 1
		k += d[a]+1
		b -= c[a] + 2


print(k)

Submission status: Wrong Answer

Solution code:
def subsolve(n, x):
    if(n < 0):
        return 0
    if(x <= 1): # level 1
        return 0
    L1 = (1 << (n + 1)) - 3
    Ps = (1 << n) - 1
    if(x >= 2 * L1 + 2): # level 5
        return 2 * Ps + 1
    if(x > L1 + 2): #level 4
        return Ps + subsolve(n - 1, x - L1 - 2) + 1
    if(x == L1 + 2): # level  3
        return Ps + 1
    return subsolve(n - 1, x - 1) # level 2
if __name__ == '__main__':
    n, x = map(int, input().split())
    print(subsolve(n, x))

Submission status: Wrong Answer

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

b = [1]
l = [1]
for i in range(n):
    b.append(b[-1]*2+1)
    l.append(l[-1]*2+3)
b.append(0)
x -= 1
res = 0
lv = n
while lv >= 0:
    #print(x,lv,l[lv],b[lv],res)
    if x <= 0:
        break
    elif lv == 0:
        res += 1
        break
    elif x == l[lv] // 2:
        res += b[lv-1] + 1
        break
    elif x > l[lv] // 2:
        res += b[lv-1] + 1
        lv -= 1
        x -= l[lv] + 2
    else:
        lv -= 1
        x -= 1
print(res)