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:
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    N, X = map(int, input().split())
    nums = [None] * (N+1)# nums[i]: i次元バーガーの層の数
    pnums = [None] * (N+1)# pnums[i]: i次元バーガーのパティの枚数
    nums[0] = 1
    pnums[0] = 1
    for i in range(N):
        nums[i+1] = nums[i]*2 + 3
        pnums[i+1] = pnums[i]*2 + 1
    
    ans = 0
    while N >= 0:
        if X == 1:
            print(ans)
            break
        elif X <= nums[N-1]+1:# N-1次元バーガの中をさらに探索
            X -= 1
            N -= 1
        elif X == nums[N-1]+2:# ぴったり真ん中のパティまで到達
            print(ans+pnums[N-1]+1)
            break
        elif X < nums[N]:
            X -= nums[N-1]+2
            ans += pnums[N-1]+1
            N -= 1
        else:
            print(ans+pnums[N])
            break
    # print(N,X)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#coding:utf-8
import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

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


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

    print(f(N,X))

    



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

# print(a, p)

def f(N, X):
    if N == 0:
        return 0 if X <= 0 else 1
    elif X <= a[N-1]:
        #端のバンズを消すのでXから1引く
        return f(N-1, X-1)
    else:
        #N-1層のパティ数＋真ん中のパティ＋... X-2-a[i]は追加したBPと下側のN-1層の分を引く
        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(p[i] * 2 + 1)

# print(a, p)

def f(N, X):
    if N == 0:
        return 0 if X <= 0 else 1
    elif X <= a[N-1]:
        #端のバンズを消すのでXから1引く
        return f(N-1, X-1)
    else:
        #N-1層のパティ数＋真ん中のパティ＋... X-2-a[i]は追加したBPと下側のN-1層の分を引く
        return p[N-1]+1+f(N-1, X-2-a[i])
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(p[i] * 2 + 1)

# print(a, p)

def f(N, X):
    if N == 0:
        return 1
    elif X <= a[N-1]:
        #端のバンズを消すのでXから1引く
        return f(N-1, X-1)
    else:
        #N-1層のパティ数＋真ん中のパティ＋... X-2-a[i]は追加したBPと下側のN-1層の分を引く
        return p[N-1]+1+f(N-1, X-2-a[i])
print(f(N, X))

Submission status: Wrong Answer

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

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N,X=mi()

    stack = [(N,X)]
    res = 0
    while stack:
        n,x = stack.pop()
        if n == 0: return 1
        c = 2**(n+2)-3
        half = c//2

        if x <= half:
            if x == 1:
                res += 0
            else:
                stack.append((n-1,x-1))
        elif x == half+1:
            res += 2**(n-1+1) - 1 + 1
        elif x < c:
            stack.append((n-1,x-(half+1)))
            res += 2**(n-1+1) - 1 + 1
        else:
            assert x == c
            res += 2**(n+1)-1


    print(res)



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

p = [0] * (n + 1)
b = [0] * (n + 1)
p[0] = 1
b[0] = 0

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


def rec(l, p, b):
    global x, ans
    if l < 0 or x <= 0:
        return

    if x >= p[l] + b[l]:
        x -= p[l] + b[l]
        ans += p[l]
        return

    x -= 1
    if x <= 0:
        return
    rec(l - 1, p, b)
    if x <= 0:
        return
    ans += 1
    x -= 1
    rec(l - 1, p, b)
    x -= 1
    return


ans = 0
rec(n, p, b)

print(ans)

Submission status: Wrong Answer

Solution code:
def solve(n, x):
    if x == 1:
        return 0
    elif 1 < x <= 1 + layer[n-1]:
        return solve(n-1, x-1)
    elif x == 2 + layer[n-1]:
        return patty[n-1] + 1
    elif 2 + layer[n-1] < x <= 2 + 2 * layer[n-1]:
        return solve(n-1, x-layer[n-1]-2) + patty[n-1] + 1
    else:
        return 2 * patty[n-1] + 1


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

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

print(solve(N, X))

Submission status: Wrong Answer

Solution code:
def solve(n, x):
    if x == 1:
        return 0
    elif 1 < x <= 1 + layer[n-1]:
        return solve(n-1, x-1)
    elif x == 2 + layer[n]:
        return patty[n-1] + 1
    elif 2 + layer[n-1] < x <= 2 + 2 * layer[n-1]:
        return solve(n-1, x-layer[n-1]-2) + patty[n-1] + 1
    else:
        return 2 * patty[n-1] + 1


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

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

patty = [1]
for _ in range(N):
    patty.append(patty[-1] * 2 + 1)

print(solve(N, X))

Submission status: Wrong Answer

Solution code:
def solve(n, x):
    if x == 0:
        return 0
    elif 0 < x < layer[n] // 2:
        return solve(n-1, x-1)
    elif x == layer[n] // 2:
        return solve(n-1, x-2) + 1
    elif layer[n] // 2 < x < layer[n] - 1:
        return solve(n-1, x-layer[n-1]-2) + patty[n-1]
    else:
        return patty[n]


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

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

patty = [1]
for _ in range(N):
    patty.append(patty[-1] * 2 + 1)

print(solve(N, X-1))

Submission status: Wrong Answer

Solution code:
n,x = map(int,input().split())
a = [1]
p = [1]
for i in range(n):
    a.append(2*a[i]+3)
    p.append(2*p[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 == 2 + a[n-1]:
        return 1+p[n-1]
    elif 2 + a[n-1] < x <= 2+2*a[n-1]:
        return p[n-1]+1+f(n-1,x-2-a[n-1])
    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())
l=[1]
for i in range(50): l+=[l[-1]*2+3]
from functools import lru_cache
@lru_cache(None)
def f(n,x):
  if n<1: return x>0
  if x<=l[n]//2: return f(n-1,x-1)
  return f(n-1,l[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())
ans = 0
c = 0

l = 1
while l <= x:
	l = 2*l + 3
	c += 1
ans = 1
for i in range(c-1):
	ans = 2*ans + 1
for i in range(n-c+1):
	ans -= 1 
print(ans)

Submission status: Wrong Answer

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

def cnt(n,x):
	if n==0:
		return 0
	m=(B[n]+1)//2
	if x<m:
		return cnt(n-1,x-1)
	elif x==m:
		return P[n-1]+1
	elif x>m:
		return P[n-1]+1+cnt(n-1, x-m) 

print(cnt(n,x))

Submission status: Wrong Answer

Solution code:
from functools import lru_cache
n, x = map(int, input().split())

@lru_cache(None)
def d(k):
    if k == 0:
        return 1
    return 2 * d(k-1) + 3

@lru_cache(None)
def f(i, h):
    if h == 0:
        return i
    rv = 0
    if i >= 1:
        rv += f(min(i - 1, d(h-1)), h - 1)
    if i >= 1 + d(h - 1):
        rv += 1 + f(min(i-1-d(h-1), d(h-1)), h-1)
    return rv

print(f(x, n))

Submission status: Wrong Answer

Solution code:
[n,x] = [int(i) for i in input().split()]
bg = ["P"]
ls = [1]
pts = [1]

for i in range(50):
    ls.append(2 * ls[-1] + 3)
    pts.append(2 * pts[-1] + 1)

ans = 0

while n > 0 and x >= 0:
    if x < ls[n]//2:
        x -= 1
        n -= 1
    elif x == ls[n]//2:
        x = -1
        ans += pts[n-1]
    else:
        x -= ls[n]//2
        ans += pts[n-1]+1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from io import StringIO
import unittest
import os

# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)

burger_cnt_list = []
patty_cnt_list = []


# 実装を行う関数
def rec(n, x) -> int:
    global burger_cnt_list
    global patty_cnt_list
    ans = 0

    x -= 1
    if x <= 0:
        return ans

    # 対象レベル-1を食べる
    if n == 0:
        x == 0
        ans += 1
    elif burger_cnt_list[n - 1] <= x:
        # 全部食べる場合
        ans += patty_cnt_list[n - 1]
        x -= burger_cnt_list[n - 1]
    else:
        # 一部しか食べない場合は再帰
        ans += rec(n - 1, x)

    if x <= 0:
        return ans

    x -= 1
    ans += 1

    if x <= 0:
        return ans

    # 対象レベル-1を食べる
    if n == 0:
        x == 0
        ans += 1
    elif burger_cnt_list[n - 1] <= x:
        # 全部食べる場合
        ans += patty_cnt_list[n - 1]
        x -= burger_cnt_list[n - 1]
    else:
        # 一部しか食べない場合は再帰
        ans += rec(n - 1, x)

    x -= 1
    if x <= 0:
        return ans

    return ans


def resolve():
    global burger_cnt_list
    global patty_cnt_list

    # 数値取得サンプル
    #   1行N項目 x, y = map(int, input().split())
    #   N行N項目 x = [list(map(int, input().split())) for i in range(n)]

    # 文字取得サンプル
    #   1行1項目 x = input()

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

    # レベル0はパティ1のみ(漸化式の初期値設定)
    burger_cnt_list.append(1)
    patty_cnt_list.append(1)
    # 全レベルの バン + パティ数とパティ数を取得
    for i in range(1, 51, 1):
        burger_cnt_list.append(3 + burger_cnt_list[i - 1] * 2)
        patty_cnt_list.append(1 + patty_cnt_list[i - 1] * 2)

    print(rec(n, x))


# テストクラス
class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """2 7"""
        output = """4"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """1 1"""
        output = """0"""
        self.assertIO(test_input, output)

    def test_input_3(self):
        test_input = """50 4321098765432109"""
        output = """2160549382716056"""
        self.assertIO(test_input, output)

    # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
    def tes_t_1original_1(self):
        test_input = """データ"""
        output = """データ"""
        self.assertIO(test_input, output)


# 実装orテストの呼び出し
if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main()

Submission status: Wrong Answer

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

ls = [1]
pts = [1]

for i in range(50):
    ls.append(2 * ls[-1] + 3)
    pts.append(2 * pts[-1] + 1)
ans = 0

while n != 0:
    if x < ls[n]//2:
        x -= 1
    elif x == ls[n]//2:
        x = 0
        ans += pts[n-1]
    else:
        x -= (ls[n]//2 + 1)
        ans += pts[n-1]+1
    n -= 1

print(ans)

Submission status: Wrong Answer

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

ls = [1]
pts = [1]

for i in range(50):
    ls.append(2 * ls[-1] + 3)
    pts.append(2 * pts[-1] + 1)
ans = 0

while n != 0 and x != 0:
    if x < ls[n]//2:
        x -= 1
    elif x == ls[n]//2:
        x = 0
        ans += pts[n-1]
    else:
        x -= (ls[n]//2 + 1)
        ans += pts[n-1]+1
    n -= 1

print(ans)

Submission status: Wrong Answer

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

ls = [1]
pts = [1]

for i in range(50):
    ls.append(2 * ls[-1] + 3)
    pts.append(2 * pts[-1] + 1)

ans = 0

while n != 0:
    if x < ls[n]//2:
        x -= 1
    elif x == ls[n]//2:
        ans += pts[n-1]+1
    else:
        x -= (ls[n]//2 + 1)
        ans += pts[n-1]+1
    n -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
num = [1]
for i in range(1, 50):
  num.append(2 * num[i - 1] + 3)
def count_p(level, x):
  if level == 1:
    if x == 5:
      return 3
    elif x == 0:
      return 0
    else:
      return x - 1
  if x < num[level - 1] + 1:
    return count_p(level - 1, x - 1)
  if x == num[level - 1] + 1:
    return 2 ** level
  if x >= num[level - 1] * 2 + 2:
    return 2 ** (level + 1) - 1
  if x >= num[level - 1] + 2:
    return 2 ** level + count_p(level - 1, x - num[level - 1] - 2)


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

Submission status: Wrong Answer

Solution code:
num = [1]
for i in range(1, 50):
  num.append(2 * num[i - 1] + 3)
def count_p(dim, x):
  if x <= 0:
    return 0
  if dim == 1:
    if x >= 2:
      return 1
    else:
      return 0
  if x < num[dim - 1] + 1:
    return count_p(dim - 1, x - 1)
  if x == num[dim - 1] + 1:
    return 2 ** dim
  if x >= num[dim - 1] + 2:
    return 2 ** dim + count_p(dim - 1, x - num[dim - 1] - 2)


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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
temp="P"
for i in range(n):
  temp="B"+temp+"P"+temp+"B"
  if len(temp)+1>x:
    break
ans=temp.count("P",0,x)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main():
    n, m = map(int, readline().split())
    div = []
    for i in range(1, int(m**0.5)+1): 
        if m%i == 0:
            div.append(i)
            div.append(m//i)

    ans = 0
    for d in div:
        if m//n >= d:    
            ans = max(ans, d)
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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


p=0
while x!=0:
    if n==0:
        p+=1
        x=0
    elif x<=h[n-1]+2:
        x=x-1
    elif x<=2*h[n-1]+2:
        p+=bp[n-1][1]+1
        x=x-h[n-1]-2
    else:
        p+=2*bp[n-1][1]+1
        x=0
    n=n-1

print(p)

Submission status: Wrong Answer

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

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


p=0
while x!=0:
    if x-1<=h[n-1]:
        x=x-1
    elif x-1<=2*h[n-1]+1:
        p+=bp[n-1][1]+1
        x=x-h[n-1]-2
    else:
        p+=2*bp[n-1][1]+1
        x=0
    n=n-1

print(p)

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline

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

T = [0] * (N + 1) # レベルiバーガーの厚さ
P = [0] * (N + 1) # レベルiバーガーのパティの数

T[1] = 5
P[1] = 3

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

# Nバーガー,X枚目
stack = [[N,X]]
ans = 0

while stack:
  n, x = stack.pop()
  if n == 1:
    ans += min(x - 1,3)
    continue
  if x <= 1: # 1枚目の場合はパティなし
    continue
  if x <= 1 + T[n - 1]: # 一つ目のレベルn - 1バーガーに収まる場合
    stack.append([n - 1, x - 1])
  if 1 + T[n - 1] <= x:
    ans += P[n - 1]
  if 2 + T[n - 1] <= x:
    ans += 1
  if 2 + T[n - 1] < x:
    stack.append([n - 1, x - (T[n - 1] + 2)])

print(ans)

Submission status: Wrong Answer

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

    # p_n = 1 + 2 * p_n-1
    # l_n = 3 + 2 * p_n-1
    # p0 = 1
    # l0 = 1
    p = [0] * (n + 1)
    l = [0] * (n + 1)
    p[0] = 1
    l[0] = 1
    for i in range(1, n + 1):
        p[i] = 1 + 2 * p[i - 1]
        l[i] = 3 + 2 * l[i - 1]

    res = 0
    while n and x > 0:
        x -= 1  # bands
        
        if x == l[n - 1] or x == l[n - 1] + 1:
            res += p[n - 1] + (x - l[n - 1])
            break
        if x < l[n - 1]:
            n -= 1
        else:
            res += p[n - 1] + 1
            x -= l[n - 1]

    print(res)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, x = list(map(int, readline().split()))
    l = [0] * (n + 1)
    b = [0] * (n + 1)

    l[0] = 1
    b[0] = 1

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

    ans = 0
    rem = x
    level = n - 1

    while rem:
        if rem >= l[level] + 2:
            ans += b[level] + 1
            rem -= (l[level] + 2)
            level -= 1
        elif rem == l[level] + 1:
            rem -= (l[level] + 1)
            ans += b[level]
        else:
            rem -= 1
            level -= 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

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

def solve(n,x):
    if n == 0:
        if x == 1:
            return 1
        return 0
    if x >= a[n]//2+1:
        return b[n-1] + 1 + solve(n-1,x-a[n]//2-1)
    if x >= 1:
        return solve(n-1,x-1)
    return 0

print(solve(N,X))

Submission status: Wrong Answer

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

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

def f(n, x):
    if n == 1:
        if 2 <= x and x <= 4:
            return x-1
        else:
            return 0
    if x == 1:
        return 0
    elif 1 < x and x <= 1 + a[n-1]:
        return f(n-1, x-1)
    elif x == 2 + a[n-1]:
        return p[n-1] + 1
    elif 2 + a[n-1] < x and x < a[n]:
        return p[n-1] + 1 + f(n-1, x - (2 + a[n-1]))
    else:
        return p[n]
print(f(n, x))

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def solve(i, x):  # レベルiバーガーの下からxこ
	if x == 0:
		return 0
	if x <= L[i-1]+1:
		ret = solve(i-1, x-1)
	else:
		ret = P[i-1]+1+solve(i-1, x-L[i-1]-2)
	return ret

N, X = MAP()
L = [0]*(N+1)
L[0] = 1
for i in range(1, N+1):
	L[i] = 2*L[i-1]+3
P = [0]*(N+1)
P[0] = 1
for i in range(1, N+1):
	P[i] = 2*P[i-1]+1

print(solve(N, X))

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def solve(i, x):  # レベルiバーガーの下からxこ
	if i == 0:
		return 0
	if x <= L[i-1]+1:
		ret = solve(i-1, x-1)
	else:
		ret = P[i-1]+1+solve(i-1, x-L[i-1]-2)
	return ret

N, X = MAP()
L = [0]*(N+1)
L[0] = 1
for i in range(1, N+1):
	L[i] = 2*L[i-1]+3
P = [0]*(N+1)
P[0] = 1
for i in range(1, N+1):
	P[i] = 2*P[i-1]+1

print(solve(N, X))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
n, x = [int(x) for x in input().split()]

total = [1]
p = [1]

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

ans = 0

def solve(x, i):
    global ans
    if i <= 1 + total[x - 1]:
        if i - 1 > 0:
            solve(x - 1, i - 1)
    else:
        ans += 1 + p[x - 1]
        if i - (2 + total[x - 1]) > 0:
            solve(x - 1, i - (2 + total[x - 1]))

solve(n, x)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

n, x = [int(x) for x in input().split()]

total = [1]
p = [1]

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

ans = 0

def solve(x, i):
    global ans
    if i <= 1 + total[x - 1]:
        if i - 1 > 0:
            solve(x - 1, i - 1)
    else:
        ans += 1 + p[x - 1]
        if i - (2 + total[x - 1]) > 0:
            solve(x - 1, i - (2 + total[x - 1]))

solve(n, x)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

arr=[1]*(n+1)
patty=[1]*(n+1)
for i in range(n):
    arr[i+1]=3+2*arr[i]
    patty[i+1]=1+2*patty[i]

def f(n,x):
    
    if x==0 or x==1 or x==-1:
        return 0
    if n==0:
        return 1
    elif x<arr[n]//2+1:
        return f(n-1,x-1)
    elif x==arr[n]//2+1:
        return patty[n-1]+1
    else:
        return patty[n]-f(n-1,arr[n]-x-1)

print(f(n,x))

Submission status: Wrong Answer

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

arr=[1]*(n+1)
patty=[1]*(n+1)
for i in range(n):
    arr[i+1]=3+2*arr[i]
    patty[i+1]=1+2*patty[i]

def f(n,x):
    
    if x==0 or x==1:
        return 0
    if n==0:
        return 1
    elif x<arr[n]//2+1:
        return f(n-1,x-1)
    elif x==arr[n]//2+1:
        return patty[n-1]+1
    else:
        return patty[n]-f(n-1,arr[n]-x-1)

print(f(n,x))

Submission status: Wrong Answer

Solution code:
pa = [1]
atu = [1]

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

Submission status: Wrong Answer

Solution code:
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n, x = ns()
    lim = 51
    total = [int(0) for _ in range(lim)]
    P_total = [int(0) for _ in range(lim)]

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

    P_total[0] = 1
    for i in range(1, lim):
        P_total[i] = P_total[i - 1] * 2 + 1

    ans = 0
    base = 1
    L = n
    while base != x and L != 0:
        if base + total[L] // 2 <= x:
            base += total[L] // 2
            ans += P_total[L - 1] + 1
        else:
            base += 1
            L -= 1
            if L == 0:
                ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n, x = ns()
    lim = 51
    total = [int(0) for _ in range(lim)]
    P_total = [int(0) for _ in range(lim)]

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

    P_total[0] = 1
    for i in range(1, lim):
        P_total[i] = P_total[i - 1] * 2 + 1

    ans = 0
    base = 1
    L = n
    while base != x and L != 0:
        if base + total[L] // 2 <= x:
            base += total[L] // 2 + 1
            ans += P_total[L - 1] + 1
            L -= 1
        else:
            base += 1
            L -= 1
            if L == 0:
                ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n, x = ns()
    lim = 51
    total = [int(0) for _ in range(lim)]
    P_total = [int(0) for _ in range(lim)]

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

    P_total[0] = 1
    for i in range(1, lim):
        P_total[i] = P_total[i - 1] * 2 + 1

    ans = 0
    base = 1
    L = n
    while base != x and not L == 0:
        if base + total[L] // 2 <= x:
            base += total[L] // 2
            ans += P_total[L - 1] + 1
        else:
            base += 1
            L -= 1
            if L == 0:
                ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n, x = ns()
    lim = 51
    total = [int(0) for _ in range(lim)]
    P_total = [int(0) for _ in range(lim)]

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

    P_total[0] = 1
    for i in range(1, lim):
        P_total[i] = P_total[i - 1] * 2 + 1

    ans = 0
    base = 1
    L = n
    while base != x or L == 0:
        if base + total[L] // 2 <= x:
            base += total[L] // 2
            ans += P_total[L - 1] + 1
        else:
            base += 1
            L -= 1
            if L == 0:
                ans += 1

    print(ans)


if __name__ == '__main__':
    main()