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:
import bisect
from math import ceil

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

hambargers = [1]
patties = [1]

for i in range(1, n+1):
    num = hambargers[i-1] * 2 + 3
    patty_num = patties[i-1] * 2 + 1
    hambargers.append(num)
    patties.append(patty_num)

index = bisect.bisect_left(hambargers, x)

if index == 0:
    print(0)
    exit()

for i in range(50):
    if index == 1:
        if x >= 4:
            ans += 3
        elif x == 3:
            ans += 2
        elif x == 2:
            ans += 1
        break
    if x < ceil(hambargers[index]/2):
        index -= 1
        continue
    elif x > ceil(hambargers[index]/2):
        ans += (patties[index-1] + 1)
        x -= ceil(hambargers[index]/2)
        index -= 1
    else:
        print(ans + patties[index-1] + 1)
        exit()
    if index == 0:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

a,x=MI()
size=[0 for i in range(a+1)]
size[0]=1
for i in range(a):
    size[i+1]=size[i]*2+3
#print(size)
#print(size[1])
patty=[0 for i in range(a+1)]
patty[0]=1
for i in range(a):
    patty[i+1]=2*patty[i]+1

def porb(k,n):
    if k==1 and n==0:
        return 0
    elif k==1:
        return 0
    elif k==size[n]:
        return patty[n]
    elif k>(size[n]+1)//2:
        return patty[n-1]+1+porb(k-(size[n]+1)//2,n-1)
    elif k==(size[n]+1)//2:
        return patty[n-1]+1
    else:
        return porb(k-1,n-1)

print(porb(x,a))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(1000000)
def main():
    N, X = (int(_) for _ in input().split())

    ex2 = []
    num = 1
    for i in range(51):
        ex2.append(num)
        num *= 2

    def Height(L):
        return 4 * ex2[L] - 3

    def TotalPatty(L):
        return 2 * ex2[L] - 1

    def NumPatty(L, x):
        M = Height(L)
        m = (M+1)//2
        if x == 1: return 0
        elif x == m: return TotalPatty(L-1) + 1
        elif x == M: return 2*TotalPatty(L-1) + 1
        elif 1 < x < m: return NumPatty(L-1, x-1)
        else: return TotalPatty(L-1) + 1 + NumPatty(L-1, x-(Height(L-1)+2))

    print(NumPatty(N, X))
    return

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
# ----------------------------------------------------------- #

n, x = Is()
Blen = [0]*(n+1)
P = [0]*(n+1)
Blen[0] = 1
P[0] = 1
for i in range(1, n):
    Blen[i] = Blen[i-1]*2 + 3
    P[i] = P[i-1]*2 + 1
def burger(i, y):
    if i == 0:
        return 0 if y <= 0 else 1
    if y < Blen[i-1] + 1:
        return burger(i-1, y-1)
    else:
        return P[i-1] + 1 + burger(i-1, y-Blen[i-1]-2)
print(burger(n, x))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
# ----------------------------------------------------------- #

n, x = Is()
Blen = [0]*(n+1)
P = [0]*(n+1)
Blen[0] = 1
P[0] = 1
for i in range(1, n):
    Blen[i] = Blen[i-1]*2 + 3
    P[i] = P[i-1]*2 + 1
def burger(i, y):
    if i == 0:
        return 1 if y > 0 else 0
    if y < Blen[i-1] + 1:
        return burger(i-1, y-1)
    else:
        return P[i-1] + 1 + burger(i-1, y-Blen[i-1]-2)
print(burger(n, x))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
# ----------------------------------------------------------- #

n, x = Is()
Blen = [0]*(n+1)
P = [0]*(n+1)
Blen[0] = 1
P[0] = 1
for i in range(1, n):
    Blen[i] = Blen[i-1]*2 + 3
    P[i] = P[i-1]*2 + 1
def burger(i, y):
    if i == 0:
        return 1 if y > 0 else 0
    if y == 0:
        return 0
    if 0 < y < Blen[i-1] + 1:
        return burger(i-1, y-1)
    else:
        return P[i-1] + 1 + burger(i-1, y-Blen[i-1]-2)
print(burger(n, x))

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def f(n,x):#レベルnのx番目
    if n==1:return 1
    if x==1:return 0
    if x<=1+A[n-1]:return f(n-1,x-1)
    if x==2+A[n-1]:return P[n-1]+1
    if x<=2*A[n-1]+2:return 1+P[n-1]+f(n-1,x-A[n-1]-2)
    if x==3+2*A[n-1]:return 2*P[n-1]+1
def main():
    n,x=map(int,input().split())
    global A,P
    A=[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]
    P=[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]
    print(f(n,x))


if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def f(n,x):#レベルnのx番目
    if n==1:return 0
    if x==1:return 0
    if x<=1+A[n-1]:return f(n-1,x-1)
    if x==2+A[n-1]:return P[n-1]+1
    if x<=2*A[n-1]+2:return 1+P[n-1]+f(n-1,x-A[n-1]-2)
    if x==3+2*A[n-1]:return 2*P[n-1]+1
def main():
    n,x=map(int,input().split())
    global A,P
    A=[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]
    P=[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]
    print(f(n,x))


if __name__=='__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,x = map(int,input().split())
a_list = [1]
p_list = [1]
for i in range(n):
  a_list.append(a_list[-1] * 2 + 3)
  p_list.append(p_list[-1] * 2 + 1)
def dfs(n,x):
  if x == 1:
    return 0
  elif 2 <= x  and x <= a_list[n-1] +1:
    return dfs(n-1,x-1)
  elif x == a_list[n-1] + 2:
    return p_list[n-1] + 1
  elif a_list[n-1] + 3 <= x and x <= 2 * a_list[n-1] + 2:
    return p_list[n-1] + 1 + dfs(n-1,x - (a_list[n-1] + 2))
  else:
    return 2 * p_list[n-1] + 1
if n == 1:
  if x == 2:
    print(1)
  if x == 3:
    print(2)
  if x == 4 or x == 5:
    print(3)   
  if x == 1:
    print(0)
else:
  print(dfs(n,x))

Submission status: Wrong Answer

Solution code:
n,x = map(int,input().split())
a_list = [1]
p_list = [1]
for i in range(n):
  a_list.append(a_list[-1] * 2 + 3)
  p_list.append(p_list[-1] * 2 + 1)
def dfs(n,x):
  if x == 1:
    return 0
  elif 2 <= x  and x <= a_list[n-1] +1:
    return dfs(n-1,x-1)
  elif x == a_list[n-1] + 2:
    return p_list[n-1] + 1
  elif a_list[n-1] + 3 <= x and x <= 2 * a_list[n-1] + 2:
    return p_list[n-1] + 1 + dfs(n-1,x - (a_list[n-1] + 2))
  else:
    return 2 * p_list[n-1] + 1
  
print(dfs(n,x))

Submission status: Wrong Answer

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

lengthOfBurger = [1]
numberOfPadi = [1]

for i in range(50):
    lengthOfBurger.append(1 + lengthOfBurger[-1] + 1 + lengthOfBurger[-1] + 1)
    numberOfPadi.append(numberOfPadi[-1] + 1 + numberOfPadi[-1])

A = []
def solution(k, end):
    if end == 0:
        A.append(0)
        return 0
    if end == lengthOfBurger[k]:
        A.append(numberOfPadi[k])
        return 0
    elif end == lengthOfBurger[k] + 1:
        A.append(numberOfPadi[k] + 1)
        return 0
    if end <= lengthOfBurger[k - 1] + 1:
        return solution(k - 1, end - 1)
    elif end <= lengthOfBurger[k - 1] + 2:
        return solution(k - 1, end - 1)
    elif end <= 2 * lengthOfBurger[k - 1] + 1:
        return solution(k - 1, lengthOfBurger[k - 1]+1) + solution(k - 1, end - 2 - lengthOfBurger[k - 1])
    else:
        print("NG")
        return -1

solution(n, x)
print(sum(A))

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    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 solve(n, x):
        if n == 0:
            return 1 if x == 1 else 0

        if x < 2:
            return 0

        if a[n] < x:
            return p[n]

        if 1 + a[n] // 2 < x:
            return p[n - 1] + 1 + solve(n - 1, x - (a[n] // 2 + 1))
        elif 1 + a[n] // 2 == x:
            return p[n - 1] + 1
        else:
            return solve(n - 1, x - 1)

    print(solve(n, x))


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    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 solve(n, x):
        if n == 0:
            return 1 if x == 1 else 0
        else:
            if x == 1:
                return 0

        if a[n] < x:
            return p[n]

        if 1 + a[n] // 2 < x:
            return p[n - 1] + 1 + solve(n - 1, x - (a[n] // 2 + 1))
        elif 1 + a[n] // 2 == x:
            return p[n - 1] + 1
        else:
            return solve(n - 1, x - 1)

    print(solve(n, x))


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


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

    print(solve(n, x))


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**9)

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

def f(n):
	if n == 0:
		return 1
	return 2 * f(n-1) + 3

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

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

num = f(n)

ans = 0
while True:
	if num < 10 ** 5:
		break
	tmp = num // 2 + 1

	if x > tmp:
		ans += p(n) // 2 + 1
		x -= tmp
		num -= tmp + 1
	elif x < tmp:
		num -= tmp + 1
		x -= 1
	else:
		print(p(n-1)+1)
		sys.exit()
	n -= 1

string = f2(n)
if len(string) <= x:
	print(p(n))
else:
	for i in range(x):
		if string[i] == 'P':
			ans += 1
	print(ans)

Submission status: Wrong Answer

Solution code:
N, X = map(int, input().split())
table = [None] * (N + 1)
table[0] = (1, 1)


def check_X(x, p):
    if x >= X:
        print(p)
        exit()


def dfs(n, x, p):
    check_X(x, p)
    if table[n] is None or x + table[n][0] >= X:
        # バン
        new_x, new_p = x + 1, p

        # L-1バーガー
        new_x, new_p = dfs(n - 1, new_x, new_p)
        check_X(new_x, new_p)

        # パティ
        new_x += 1
        new_p += 1

        # L-1バーガー
        new_x, new_p = dfs(n - 1, new_x, new_p)
        
        # バン
        new_x += 1
        check_X(new_x, new_p)

        table[n] = (new_x - x, new_p - p)
        return new_x, new_p
    else:
        dx, dp = table[n]
        return x + dx, p + dp


dfs(N, 0, 0)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
n, x = map(int, input().split())
f_n = [2 ** (i + 2) - 3 for i in range(n + 1)]
p_n = [2 ** (i + 1) - 1 for i in range(n + 1)]
# print(f_n)
ans = 0
while x > 0:
    if x < f_n[n - 1] + 2:
        x -= 1
    elif x == f_n[n]:
        ans += p_n[n]
        break
    elif x == (f_n[n - 1] + 2):
        ans += p_n[n - 1] + 1
        break
    else:
        ans += p_n[n - 1] + 1
        x -= f_n[n - 1] + 2
    n -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
n, x = map(int, input().split())
f_n = [2 ** (i + 2) - 3 for i in range(n + 1)]
p_n = [2 ** (i + 1) - 1 for i in range(n + 1)]
ans = 0
while x > 0:
    if x < f_n[n - 1] + 2:
        x -= 1
    elif x == (f_n[n - 1] + 2):
        ans += p_n[n - 1] + 1
        break
    else:
        ans += p_n[n - 1] + 1
        x -= f_n[n - 1] + 2
    n -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
n, x = map(int, input().split())
f_n = [2 ** (i + 2) - 3 for i in range(n + 1)]
p_n = [2 ** (i + 1) - 1 for i in range(n + 1)]
ans = 0
while x > 0:
    if x < f_n[n - 1] + 2:
        x -= 1
    elif x == f_n[n - 1] + 2:
        ans = p_n[n - 1] + 1
        break
    else:
        ans += p_n[n - 1] + 1
        x -= f_n[n - 1] + 2
    n -= 1

print(ans)

Submission status: Wrong Answer

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

def F(N, X):
  if N < 0:
    return 0
  if X == 1:
    return 0

  if 1 < X <= a[N-1] + 1:
    return F(N-1, X-1)

  if X ==  a[N-1] + 2:
    return b[N-1] + 1

  if a[N-1] + 2 < X <= 2*a[N-1] + 2:
    return b[N-1] + 1 + F(N-1, X - 2 - a[N-1])

  if X == 2 * a[N-1] + 3:
    return 2 * b[N-1] + 1

print(F(N, X))

Submission status: Wrong Answer

Solution code:
N, X = map(int, input().split())
a = [1]
b = [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

  if 1 < X <= a[N-1] + 1:
    return F(N-1, X-1)

  if X ==  a[N-1] + 2:
    return b[N-1] + 1

  if a[N-1] + 2 < X <= 2*a[N-1] + 2:
    return b[N-1] + 1 + F(N-1, X - 2 - a[N-1])

  if X == 2 * a[N-1] + 3:
    return 2 * b[N-1] + 1

print(F(N, X))

Submission status: Wrong Answer

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

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

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

print(bur(n,x))

Submission status: Wrong Answer

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

a=[1]
p=[1]

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

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

print(bur(n,x))

Submission status: Wrong Answer

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

a=[1]
p=[1]

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

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

print(bur(n,x))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def DFS(N,X):
    if X==1:return 0
    elif N==0:return 1
    elif 1<X<=1+B[N-1]:return DFS(N-1,X-1)
    elif X==2+B[N-1]:return P[N-1]+1
    elif 2+B[N-1]<X<=2+2*B[N-1]:return P[N-1]+1+DFS(N-1,X-2-B[N-1])
    elif X==2*B[N-1]+3:return 2*P[N-1]+1


n,x=map(int,input().split())
B,P=[1],[1]

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

print(DFS(n,x))

Submission status: Wrong Answer

Solution code:
def DFS(N,X):
    if N==0:return 0
    elif X<=1+B[N-1]:
        return DFS(N-1,X-1)
    else:
        return P[N-1]+1+DFS(N-1,X-2-B[N-1])


n,x=map(int,input().split())
B,P=[1],[1]

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

print(DFS(n,x))

Submission status: Wrong Answer

Solution code:
def DFS(N,X):
    if X==1:return 0
    elif 1<X<=1+B[N-1]:return DFS(N-1,X-1)
    elif X==2+B[N-1]:return P[N-1]+1
    elif 2+B[N-1]<X<=2+2*B[N-1]:return P[N-1]+1+DFS(N-1,X-2-B[N-1])
    elif X==2*B[N-1]+3:return 2*P[N-1]+1


n,x=map(int,input().split())
B,P=[1],[1]

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

print(DFS(n,x))

Submission status: Wrong Answer

Solution code:
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)


def main():
    N, X = map(int, input().split())
    B = 1
    P = 1
    for i in range(N):
        B = 2 * B + 3
        P = 2 * P + 1

    def cnt(X, B, P, ans):
        if B == 5:
            if X == 5:
                return ans + 3
            elif X == 4:
                return ans + 3
            elif X == 3:
                return ans + 2
            elif X == 2:
                return ans + 1
            else:
                return ans
        if X > B // 2 + 1:
            ans += P // 2 + 1
            P = P // 2
            X = X - (B // 2 + 1)
            B = B // 2 - 1
            return cnt(X, B, P, ans)
        elif X == B // 2 + 1:
            ans += P // 2 + 1
            return ans
        else:
            B = B // 2 - 1
            P = P // 2
            X -= 1
            return cnt(X, B, P, ans)

    answer = cnt(X, B, P, 0)
    print(answer)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

px=lambda x:2**x+int(0.5*sum([2**(i+1) for i in range(x)]))

ans=0
i=n
while i>0 and x>0:
  if i==1 and x<=5:
    ans+='BPPPB'[:x].count('P')
    i-=1
  elif x>an-i:
    ans+=px(i)
    x-=an+2 #?
  elif x>=(an+1)//2:
    ans+=1
    an=(an+1)//2-2
    i-=1
  elif x<an-i:
    an=(an+1)//2-2
    i-=1
  
print(ans)

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
a,p=[1],[1]
for i in range(n+1):
    a.append(3+2*a[-1])
    p.append(1+2*p[-1])
def f(l,x):
    if l==0:return int(x==1)
    if x<=1+a[l-1]:
        return  f(l-1,x-1)
    else:return p[l-1]+1+f(l-1,x-2-a[l-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+1):
    a.append(3+2*a[-1])
    p.append(1+2*p[-1])
def f(l,x):
    if l==0:return int(x==1)
    if x<=1+a[n-1]:
        return  f(l-1,x-1)
    else:return p[l-1]+1+f(l-1,x-2-a[l-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+1):
    a.append(3+2*a[-1])
    p.append(1+2*a[-1])
def f(l,x):
    if l==0:return int(x==1)
    if x<=1+a[n-1]:
        return  f(l-1,x-1)
    else:return p[l-1]+1+f(l-1,x-2-a[l-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(3+2*a[-1])
    p.append(1+2*a[-1])
def f(l,x):
    if l==0:return int(x==1)
    if x<=1+a[n-1]:
        return  f(l-1,x-1)
    else:return p[l-1]+1+f(l-1,x-2-a[l-1])
print(f(n,x))

Submission status: Wrong Answer

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


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


print(paty(n, x))

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
p=[1]
q=[1]
for i in range(n):
    p.append(2*p[i]+1)
    q.append(2*q[i]+3)
def cal(n_cal,x_cal):
    if x_cal<=1:
        ret=0
    elif 1<x_cal<=q[n_cal-1]+1:
        ret=cal(n_cal-1,x_cal-1)
    elif  q[n_cal-1]+2==x_cal:
        ret=(p[n_cal-1]+1)
    elif x_cal<=2+q[n_cal-1]*2:
        ret=p[n_cal-1]+1+cal(n_cal-1,x_cal-(q[n_cal-1]+2))
    elif x_cal==3+2*q[n_cal-1]:
        ret=2*p[n_cal-1]+1
    return ret
print(cal(n,x))

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
p=[1]
q=[1]
for i in range(n):
    p.append(2*p[i]+1)
    q.append(2*q[i]+3)
def cal(n_cal,x_cal):
    if x_cal<=1:
        ret=0
        flag=1
    elif 1<x_cal<=q[n_cal-1]+1:
        ret=cal(n_cal-1,x_cal-1)
        flag=2
    elif  q[n_cal-1]+2==x_cal:
        ret=(p[n_cal-1]+1)
        flag=3
    elif x_cal<=2+q[n_cal-1]*2:
        ret=p[n_cal-1]+1+cal(n_cal-1,x_cal-(q[n_cal-1]+2))
        flag=4
    else:
        ret=2*p[n_cal-1]+1
        flag=5
    return ret
print(cal(n,x))

Submission status: Wrong Answer

Solution code:
def make(n,x):
    if n==0:
        return 1
    elif x==1:
        return 0
    elif x==b_memo[n-1]+2:
        return p_memo[n-1]+1
    elif x>=b_memo[n-1]+1:
        return p_memo[n-1]+1+make(n-1,x-b_memo[n-1]-2)
    else:
        return make(n-1,x-1)
  
n,k=map(int,input().split())
b_memo=[0]*51
p_memo=[0]*51
b_memo[0]=1
p_memo[0]=1
for i in range(50):
    b_memo[i+1]=2*b_memo[i]+3
for i in range(50):
    p_memo[i+1]=2*p_memo[i]+1

print(make(n,k))

Submission status: Wrong Answer

Solution code:
def make(n,x):
    if n==0:
        return 1
    elif x==1:
        return 0
    elif x>=b_memo[n-1]+1:
        return p_memo[n-1]+1+make(n-1,x-b_memo[n-1]-2)
    elif x<b_memo[n-1]+1:
        return make(n-1,x-1)
  
n,k=map(int,input().split())
b_memo=[0]*51
p_memo=[0]*51
b_memo[0]=1
p_memo[0]=1
for i in range(50):
    b_memo[i+1]=2*b_memo[i]+3
for i in range(50):
    p_memo[i+1]=2*p_memo[i]+1

print(make(n,k))

Submission status: Wrong Answer

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

zero = 'P'
one = 'BPPPB'
two = 'B'+ one + 'P' +  'BPPPB' + 'B'

current = one

for i in range(1, N):
    current = 'B'+ one + 'P' +  current + 'B'

eaten = current[:X]
print(eaten.count('P'))

Submission status: Wrong Answer

Solution code:
n,x = map(int, input().split())
p = [1]
l = [1]
for i in range(n):
  p += [p[i]*2 + 1]
  l += [l[i]*2 + 3]
  
def f(n,x):
  if n == 0:
    return x
  if x < 0:
    return x
  ret = 0
  if l[n-1] + 1 <= x:
    return f(n-1, x-1)
  elif l[n-1] + 2 == x:
    return p[n-1] + 1
  elif x <= l[n] - 1:
    return p[n-1] + 1 + f(n-1, x-l[n-1]-2)
  else:
    return p[n]
  
print(f(n,x))

Submission status: Wrong Answer

Solution code:
n,x = map(int, input().split())
p = [1]
l = [1]
for i in range(n):
  p += [p[i]*2 + 1]
  l += [l[i]*2 + 3]
  
def f(n,x):
  if n == 0:
    return x
  if x < 0:
    return x
  ret = 0
  if l[n-1] + 1 <= x:
    return f(n-1, x)
  elif l[n-1] + 2 == x:
    return p[n-1] + 1
  else:
    return p[n-1] + 1 + f(n-1, x-l[n-1]-2)
  
print(f(n,x))

Submission status: Wrong Answer

Solution code:
N, X = map(int, input().split())
a = [1]
for _ in range(N - 1):
    a.append(a[-1] * 2 + 3)
p = [1]
for _ in range(N - 1):
    p.append(p[-1] * 2 + 1)
# print(a)
# print(p)
def func(n, x):
    if x == 1:
        return 0
    elif x <= 1 + a[n - 1]:
        return func(n - 1, x - 1)
    elif x == 2 + a[n - 1]:
        return p[n - 1] + 1
    elif x <= 2 + a[n - 1] * 2:
        return p[n - 1] + 1 + func(n - 1, x - a[n - 1] - 2)
    else:
        return p[n - 1] * 2 + 1
if N == 0:
    print(1)
else:
    print(func(N, X))

Submission status: Wrong Answer

Solution code:
N, X = map(int, input().split())
a = [1]
for _ in range(N - 1):
    a.append(a[-1] * 2 + 3)
p = [1]
for _ in range(N - 1):
    p.append(p[-1] * 2 + 1)
# print(a)
# print(p)
def func(n, x):
    if x == 1:
        return 0
    elif x <= 1 + a[n - 1]:
        return func(n - 1, x - 1)
    elif x == 2 + a[n - 1]:
        return p[n - 1] + 1
    elif x <= 2 + a[n - 1] * 2:
        return p[n - 1] + 1 + func(n - 1, x - a[n - 1] - 2)
    else:
        return p[n - 1] * 2
if N == 0:
    print(1)
else:
    print(func(N, X))