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())
X -= 1
p = [1]*(N+1)
b = [1]*(N+1)

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


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

now_N = N-1
result = 0
start = 0
while True:
  lo_X = where_X(start, b, X, now_N)
  if lo_X == 0:
    break
  elif lo_X == 1:
    start += 1
  elif lo_X == 2:
    result += 1+p[now_N]
    break
  elif lo_X == 3:
    start += 2 + b[now_N]
    result += 1 + p[now_N]
  elif lo_X == 4:
    result += 1 + 2*p[now_N]
    break
  now_N -= 1

print(result)

Submission status: Wrong Answer

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

answer = 0
red = x

searching_index = n
while red > 0:
    for i in reversed(range(searching_index + 1)):
        length = 2**(i + 2) - 3
        if red >= length:
            print("length", length, red)
            if red >= length + 1:
                print("contain p")
                answer += 1
                red -= 1
            searching_index = i
            answer += 2**(i+1) - 1
            red -= length
            print(answer, length)
            break
        red -= 1

print(answer)

Submission status: Wrong Answer

Solution code:
def barger(m,s):
    if m==1:
        return 'B'+s+'P'+s+'B'
    else:
        return 'B'+barger(m-1,s)+'P'+barger(m-1,s)+'B'

n=input().split()
n=[int(i) for i in n]
print(n)

if n[0]==0:
    s="P"
else:
    s=barger(n[0],"P")

r=list(s)
print(r)
c=0
for i in range(0,n[1]):
    print(r[i+len(s)-n[1]])
    if r[i+len(s)-n[1]]=="P":
        c+=1
print(c)

Submission status: Wrong Answer

Solution code:
n_x = input()
n_x_list =n_x.split(' ')

N = int(n_x_list[0])
X = int(n_x_list[1])

# g_list = [''] * N
# def G(N):
#     if N == 0:
#         return 'p'
#
#     gn_1 = G(N-1)
#
#     return 'b' + gn_1 + 'p' + gn_1 + 'b'

# g_n = G(N)
# print(g_n)
# eaten_burger = g_n[0:X]
# print(eaten_burger)
# ans = eaten_burger.count('p')
# print(ans)

def L(N):
    return 2 ** (N+2) - 3

def P(N):
    return 2 ** (N+1) - 1

def solve(N, X):
    half_l = int(L(N) / 2)
    if N == 0:
        return 1

    if half_l <= 1:
        return 0
    elif X < half_l:
        return solve(N - 1, X - 1)
    elif X == half_l:
        return P(N-1)
    elif half_l + 1 == X:
        return P(N-1) + 1
    elif half_l + 1 < X:
        return P(N-1) + 1 + solve(N-1, (X - L(N-1) - 2))
    elif half_l * 2 + 3 == X:
        return 2 * P(N-1) + 1


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

Submission status: Wrong Answer

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

num = 1
pate = 1
for i in range(n):
    num = num * 2 + 3
    pate = pate * 2 + 1

def culc(l, idx, num, pate):
    npate = (pate - 1) // 2
    nnum = (num - 3) // 2
    mid = (num + 1) // 2
    if l == 1:
        if idx == 1:
            return 0
        elif idx == 2:
            return 1
        elif idx == 3:
            return 2
        elif idx == 4:
            return 3
        else:
            return 3
    elif mid == idx:
        return npate + 1
    elif mid < idx:
        return npate + 1 + culc(l - 1, idx - mid, nnum, npate)
    else:
        return culc(l - 1, idx - 1, nnum, npate)
print(culc(n, x, num, pate))

Submission status: Wrong Answer

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

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

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

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

print(solve(N, X))

Submission status: Wrong Answer

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

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

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


def cal(n, rem):
    if n == 0:
        return 1 if rem == 1 else 0
    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:
            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:
N, X = map(int, input().split())
L2 = [1]
j = 1
for i in range(N+2):
    j *= 2
    L2.append(j)
Y = 0
if N >= X:
    print(0)
    exit()
for i in range(N):
    if L2[N+1-i] - 1 == X:
        Y += L2[N-i]
        print(Y)
        break
    elif L2[N+2-i] - 3 == X:
        Y += L2[N+1-i] - 1
        print(Y)
        break
    elif L2[N+1-i] - 1 < X:
        Y += L2[N-i]
        X -= L2[N+1-i] - 1
    else:
        X -= 1
else:
    print(Y)

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
len_b=2**(n+2)-3
p=[2**(i+1)-1 for i in range(n)]
start=1
end=len_b
center=(end+1)//2
count1=0
count2=n-1
while True:
    if x==start:
        break
    elif x==center:
        count1+=p[count2]+1
        break
    elif x==end:
        count1+=p[count2]*2+1
        break
    elif x<center:
        start=start+1
        end=center-1
        center=(start+end)//2
        count2-=1
    else:
        start=center+1
        end=end-1
        center=(start+end)//2
        count1+=p[count2]+1
        count2-=1
print(count1)

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
flg = False # Lが1個目ならTrue
L = None
for i in range(n, -1, -1):
    if i+1 <= x <= i+2**(n-i+3)-3:
        flg = True
        L = i
        break
    if i+1 <= 2**(n+2)-3-x <= i+2**(n-i+3)-3:
        L = i
        break
ans = None
if flg==True:
    if x-L==1:
        ans = 0
    elif x==L+2**(n-L+3)-3:
        ans = 2**(n-L+2)-1
    else:
        ans = 2**(n-L+1)-1
else:
    if 2**(n+2)-3-x==L:
        ans = 2**(n+1)-1
    elif 2**(n+2)-3-x==L+2**(n-L+3)-3:
        ans = 2**(n+1)-2**(n-L+2)
    else:
        ans = 2**(n+1)-2**(n-L+1)
print(ans)

Submission status: Wrong Answer

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

#a[i]:leveru i no sousuuuuu
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]
#b[i]:leveru i no P sousuuuu
b = [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]


#レベルkのバーがーをしたからx枚食べたときのP
def f(k,x,a,b):
    if x == 0:
        return 0
    elif k == 0:
        return 1
    elif k== 2:
        if x <= 4:
            return x-1
        else:
            return 3
    else:
        if x == (a[k]-1)//2+1:
            return b[k-1] + 1
        elif x < (a[k]-1)//2+1:
            if x <= k:
                return 0
            else:
                return f(k-1,x-1,a,b)
        elif x >= a[k]-k:
            return b[k]
        else:
            return b[k-1] + f(k-1,x-(a[k]-1)//2-1,a,b) + 1

print(f(n,x,a,b))

Submission status: Wrong Answer

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

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

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


def cal(n, rem):
    if n == 0:
        return 0 if rem <= 0 else 1
    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:
            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:
#!/env/usr/python3
import re
import math
# P ... 0 / B ... 1
def func(Berger):
	LAST_Berger = Berger
	#print(bin(LAST_Berger))
	if Berger != 0:
		log2_Berger = int(math.log(Berger)/math.log(2)) + 1
	else:
		log2_Berger = 1
	#print("{0}: {1}".format("log2_Berger", log2_Berger))
	Berger = (1<<log2_Berger) # last "B"
	#print("[1]: {0}".format(bin(Berger)))
	Berger = Berger + LAST_Berger
	#print("[2]: {0}".format(bin(Berger)))
	Berger = (Berger<<1) + 0
	#print("[3]: {0}".format(bin(Berger)))
	Berger = (Berger<<log2_Berger) + LAST_Berger
	#print("[4]: {0}".format(bin(Berger)))
	Berger = (Berger<<1) + 1
	#print("[5]: {0}".format(bin(Berger)))
	return Berger

def one_pud(num):
	a = 1
	for i in range(num-1):
		a = (a<<1) + 1
		#print(bin(a))
	return a


def main():
	n, k = input().split()
	n = int(n)
	k = int(k)
	Berger = 0b0
	#print("hoge")
	for i in range(n):
		Berger = func(Berger)
		#print("piyo")
		#if len(Berger) >= k:
		#	Berger = Berger[k-1:]
	#print(Berger)
	#print("hoge")
	#print(bin(one_pud(k)))
	dog_Berger = Berger & one_pud(k)
	#print(bin(dog_Berger))

	log2_k = int(math.log(k)/math.log(2)) + 1
	#print(bin(dog_Berger+1<<int(log2_k)))
	#print(bin(dog_Berger+1<<int(log2_k)))
	print(len(re.findall("0", str(bin(dog_Berger)))))


main()

Submission status: Wrong Answer

Solution code:
import sys
def qwe(n,x,ans):
    n1 = "BPPPB"
    n2 = "BBPPPBPBPPPBB"
    if n==1:
        for s in n1:
            if s=="P": ans+=1
            x-=1
            if x==0:
                print(ans)
                sys.exit()
    else:
        for s in n2:
            if s=="P": ans+=1
            x-=1
            if x==0:
                print(ans)
                sys.exit()

def main():
    n,x = map(int, input().split())
    if n<=2:
        qwe(n,x,0)
    a = [1]
    b = [1]
    for i in range(n-1):
        a.append(2*a[-1]+3)
        b.append(2*b[-1]+1)
    ans = 0
    if x== 2*a[n-1]+3:
        print(2*b[n-1]+1)
        sys.exit()
    elif x==2*a[n-1]+2:
        print(2*b[n-1]+1)
        sys.exit()
    elif x == a[n-1]+2:
        print(b[n-1]+1)
        sys.exit()
    elif x== a[n-1]+1:
        print(b[n-1])
        sys.exit()
    elif x > a[n-1]+2:
        ans += b[n-1]+1
        x -= a[n-1]+2
        n = n-1
    else:
        x -=1
        n = n-1
    while n>2 or x > 0:
        if x== 2*a[n-1]+3:
            ans += 2*b[n-1]+1
            print(ans)
            sys.exit()
        elif x==2*a[n-1]+2:
            ans += 2*b[n-1]+1
            print(ans)
            sys.exit()
        if x == a[n-1]+2:
            ans += b[n-1]+1
            print(ans)
            sys.exit()
        elif x== a[n-1]+1:
            ans+=b[n-1]
            print(ans)
            sys.exit()
        elif x > a[n-1]+2:
            ans += b[n-1]+1
            x -= a[n-1]+3
            n = n-1
        else:
            x -=1
            n = n-1
    if x==0:
        print(ans)
        sys.exit()
    qwe(n,x,ans)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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):
        print(l,x)
        if x==0:
            return 0
        if (l,x) in table:
            return table[(l,x)]
        if x==lens[l]:
            res=nump[l]
        elif 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:
p_count = 0
hambagar = []

def makebarger(level, target):
  global p_count
  global hambagar
  if len(hambagar) > target:
      return
  else:
    if (level == 0):
      p_count = p_count + 1
      hambagar.append('P')
    else:
      hambagar.append('B')
      makebarger(level-1, target)
      hambagar.append('P')
      p_count = p_count + 1
      makebarger(level-1, target)
      hambagar.append('B')


level, target = map(int, input().split(' '))

makebarger(level, target)
print(p_count-1)

Submission status: Wrong Answer

Solution code:
import math
n,x = map(int,input().split())
c = 0
while x > 1:
  k = int(math.log2(x+1) -1)
  if n > k:
    x -= n-k
    n = k-1
  x = x + 3 - 2**(k+1)
  c += (2**k)-1
print(c)

Submission status: Wrong Answer

Solution code:
s = []
p = []


def eat(x, i):
    if x <= 0:
        return 0
    if i == 0:
        return 1
    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())


def search(num, x):
    pos = 0
    ans = 0
    sub = 0
    for i in range(num):
        p_center = pow(2, i+1) - 1
        if p_center > x:
            break
        else:
            pos = i
            ans = ((p_center - 1) / 2) + 1
            sub = abs(p_center - x)

    return pos, ans, sub


if __name__ == '__main__':
    answer = 0
    s = 9999999
    p = 50

    if X > N:
        while True:
            if s == 0 or s < p:
                break

            if s > 0:
                p, a, s = search(num=p, x=X)
                answer += a
                X = s

    print(int(answer))

Submission status: Wrong Answer

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

    if (b+1) / 2 < x:
        res += 2**n
        b = (b+1) / 2
    else:
        b = b - (b+1) / 2 -1
print(res)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-


def main():
    """Function."""
    n, x = map(int, input().split())

    total_len = [0 for _ in range(n + 1)]
    p_len = [0 for _ in range(n + 1)]
    total_len[0], p_len[0] = 1, 1

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

    p_counter = 0
    del_counter = x

    for _ in range(n):
        if del_counter in total_len:
            p_counter += p_len[total_len.index(del_counter)]
            break
        elif del_counter+1 in total_len:
            p_counter += p_len[total_len.index(del_counter+1)]
            break

        # print(del_counter)
        temp_len, temp_p = 0, 0
        for i in range(n):
            if total_len[i+1] > x:
                temp_len = total_len[i]
                temp_p = p_len[i]
                break

        p_counter += (temp_p)
        del_counter += -(temp_len)

        if del_counter <= 0:
            break

    print(p_counter)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
len_b=2**(n+2)-3
p=[2**(i+1)-1 for i in range(n+1)]
start=1
end=len_b
center=(end+1)//2
count1=0
count2=n-1
while True:
    if x==start:
        break
    elif x==center:
        count1+=p[count2]+1
        break
    elif x==end:
        count1+=p[count2]*2+1
        break
    elif x<center:
        start=start+1
        end=center-1
        center=(start+end)//2
        count2-=1
    else:
        start=center+1
        end=end-1
        center=(start+end)//2
        count1+=p[count2]
        count2-=1
print(count1)

Submission status: Wrong Answer

Solution code:
import numpy as np
N, X = map(int,input().split())
# あまりt
n_p=0
if X >= N:
    while (X>4):
        n = int(np.floor(np.log2((X+3)/4)))
        X -= (4*2**n-3)
        print(n)
        n_p += 2**(n+1)-1
    n_p += (X-1)
print(n_p)

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
flg = False # Lが1個目ならTrue
L = None
for i in range(n+1):
    if i+1 <= x <= i+2**(n-i+3)-3:
        flg = True
        L = i
        break
    if i+1 <= 2**(n+2)-3-x <= i+2**(n-i+3)-3:
        L = i
        break
print(L)
ans = None
if flg==True:
    if x-L==1:
        ans = 0
    elif x==L+2**(n-L+3)-3:
        ans = 2**(n-L+2)-1
    else:
        ans = 2**(n-L+1)-1
else:
    if 2**(n+2)-3-x==L:
        ans = 2**(n+1)-1
    elif 2**(n+2)-3-x==L+2**(n-L+3)-3:
        ans = 2**(n+1)-2**(n-L+2)
    else:
        ans = 2**(n+1)-2**(n-L+1)
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import numpy as np
N,X=[int(x) for x in stdin.readline().rstrip().split()]
burger_set=np.array(["P"])
for i in range(N):
    new_burger="B"+burger_set[0]+"P"+burger_set[0]+"B"
    burger_set[0]=(new_burger)
ans=burger_set[0][0][0:X].count('P')
print(ans)

Submission status: Wrong Answer

Solution code:
n_x = input()
n_x_list =n_x.split(' ')

N = int(n_x_list[0])
X = int(n_x_list[1])

# g_list = [''] * N
# def G(N):
#     if N == 0:
#         return 'p'
#
#     gn_1 = G(N-1)
#
#     return 'b' + gn_1 + 'p' + gn_1 + 'b'

# g_n = G(N)
# print(g_n)
# eaten_burger = g_n[0:X]
# print(eaten_burger)
# ans = eaten_burger.count('p')
# print(ans)

def L(N):
    return 2 ** (N+2) - 3

def P(N):
    return 2 ** (N+1) - 1

def solve(N, X):
    half_l = int(P(N) / 2)
    if N == 0:
        return 1

    if half_l > X:
        return solve(N - 1, X - 1)
    elif half_l == X:
        return P(N-1)
    elif half_l + 1 == X:
        return P(N-1) + 1
    elif half_l + 1 < X:
        return P(N-1) + 1 + solve(N-1, (X - L(N-1) - 2))
    elif half_l * 2 + 1 == X:
        return 2 * P(N-1) + 1


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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

def n_all(level):
    return (1 << (level + 2)) - 3

def n_patty(level):
    return (1 << (level + 1)) - 1

p_sum = 0
X_tmp = X

for lv in range(N, 0, -1):
    center = int(n_all(lv) / 2)
    if X_tmp == 0:
        break
    elif X_tmp == n_all(lv):
        p_sum += n_patty(lv)
        break
    elif X_tmp == center:
        p_sum += int((n_patty(lv) + 1) / 2)
        break
    else: 
        X_tmp -= int((n_all(lv) + 1) / 2)
        p_sum += int((n_patty(lv) + 1) / 2)
        
print(p_sum)

Submission status: Wrong Answer

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

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

st = 0
ed = ln[n]-1

ans = 0
while ed-st > 0:
    half = st + (ed-st)//2
    
    if x-1 == half:
        ans += ((half-st)//2 + 1)
        break
        
    elif x-1 < half:
        st += 1
        ed = half-1
        
    else:
        ans += ((half-st)//2 + 1)
        st = half+1
        ed -= 1
        
print(ans)

Submission status: Wrong Answer

Solution code:
# 違う
N, X = map(int, input().split())
remain = X % 4
if X == 0:
    print(int(X / 2 - 1))
elif X == 1:
    print(int((X - 1) / 2))
elif X == 2:
    print(int(X / 2))
else:
    print(int((X + 1) / 2))

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]:
            res=nump[l]
        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:
n,x = map(int, input().split())
print([0,x//2+[2,3][x%2 == 0]][x != 1])

Submission status: Wrong Answer

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

lays = [0]*(N+1)
lays[0] = 1
pats = lays[:]
patsum = 0

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

for i in range(N):
    if X == 1:
        break
    elif X == lays[N-i]:
        patsum += pats[N-i]
        break
    elif X == lays[N-i]//2+1:
        patsum += (pats[N-i-1]+1)
        break
    elif X > lays[N-i]//2+1:
        patsum += (pats[N-i-1]+1)
        X -= (lays[N-i-1]+2)
    else:
        X -= 1
print(patsum)

Submission status: Wrong Answer

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

cnt = [0,1]
tmp = [[0,1]]

for i in range(n):

    tmp.append([cnt[0] * 2 + 2,cnt[1] * 2 + 1])
    cnt[0] = cnt[0] * 2 + 2
    cnt[1] = cnt[1] * 2 + 1

"""
半分に区切ってジャスト半分なら前の分+1を出力
大きければ前の分+1を足して次
小さければ数える数を1小さくしてレベルを下げる
"""
num = 0
for i in range(n,0,-1):
    if (sum(tmp[i])+1)/2 == k:
        num += tmp[i-1][1]+1
        break
    elif (sum(tmp[i])-1)/2 == k:
        num += tmp[i-1][1]
        break
    elif sum(tmp[i]) == k or sum(tmp[i]) == k:
        num += tmp[i][1]
        break
    elif (sum(tmp[i])-1)/2 < k:
        num += tmp[i-1][1]+1
        k = k - sum(tmp[i-1]) - 2
    elif (sum(tmp[i])-1)/2 > k:
        k = k - 1
print(num)

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
len_b=2**(n+2)-3
p=[2**(i+1)-1 for i in range(n+1)]
start=1
end=len_b
center=(end+1)//2
count1=0
count2=n-1
while True:
    if x==start:
        break
    elif x==center:
        count1+=p[count2]+1
        break
    elif x==end:
        count1+=p[count2]*2+1
        break
    elif x<center:
        start=start+1
        end=center-1
        center=(start+end+1)//2
        count2-=1
    else:
        start=center+1
        end=end-1
        center=(start+end+1)//2
        count1+=p[count2]
        count2-=1
print(count1)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import numpy as np
N,X=[int(x) for x in stdin.readline().rstrip().split()]
burger_set=np.array(["P"])
for i in range(N):
    new_burger="B"+burger_set[0]+"P"+burger_set[0]+"B"
    burger_set[0]=(new_burger)
ans=burger_set[0][0:X].count('P')
print(ans)

Submission status: Wrong Answer

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

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

st = 0
ed = ln[n]-1

ans = 0
while True:
    half = st + (ed-st)//2
    
    if x == half:
        ans += ((half-st)//2 + 1)
        break
        
    elif x < half:
        st += 1
        ed = half-1
        
    else:
        ans += ((half-st)//2 + 1)
        st = half+1
        ed -= 1
        
print(ans)

Submission status: Wrong Answer

Solution code:
n,x = map(int, input().split())
print([0,x//4+3][x != 1])

Submission status: Wrong Answer

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

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

st = 0
ed = ln[n]-1

ans = 0
while ed-st > 0:
    half = st + (ed-st)//2
    
    if x == half:
        ans += ((half-st)//2 + 1)
        break
        
    elif x < half:
        st += 1
        ed = half-1
        
    else:
        ans += ((half-st)//2 + 1)
        st = half+1
        ed -= 1
        
print(ans)

Submission status: Wrong Answer

Solution code:
def burg(n,x):
	b = {0:'P'}
	ps = {0:1}
	for i in range(1,n+1):
		ps[i] = ps[i-1]*2 + 1
	return ps[n]//x

l = input().split(' ')
n,x = int(l[0]),int(l[1])

print(burg(n,x))

Submission status: Wrong Answer

Solution code:
import sys
def qwe(n,x,ans):
    n1 = "BPPPB"
    n2 = "BBPPPBPBPPPBB"
    if n==1:
        for s in n1:
            if s=="P": ans+=1
            x-=1
            if x==0:
                print(ans)
                sys.exit()
    else:
        for s in n2:
            if s=="P": ans+=1
            x-=1
            if x==0:
                print(ans)
                sys.exit()

def main():
    n,x = map(int, input().split())
    if n<=2:
        qwe(n,x,0)
    a = [1]
    b = [1]
    for i in range(n-1):
        a.append(2*a[-1]+3)
        b.append(2*b[-1]+1)
    ans = 0
    if x == a[n-1]+2:
        print(b[n-1]+1)
        sys.exit()
    elif x== a[n-1]+1:
        print(b[n-1])
        sys.exit()
    elif x > a[n-1]+2:
        ans += b[n-1]+1
        x -= a[n-1]+2
        n = n-1
    else:
        x -=1
        n = n-1
    while n>2 or x > 0:
        if x == a[n-1]+2:
            ans += b[n-1]+1
            print(ans)
            sys.exit()
        elif x== a[n-1]+1:
            ans+=b[n-1]
            print(ans)
            sys.exit()
        elif x > a[n-1]+2:
            ans += b[n-1]+1
            x -= a[n-1]+2
            n = n-1
        else:
            x -=1
            n = n-1
    if x==0:
        print(ans)
        sys.exit()
    qwe(n,x,ans)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

for i in range(n-1, 0, -1):
    x -= 1
    g = (2 << i) - 1
    h = (2 << (i + 1)) - 3
    if x > h:
        res += g + 1
        x -= h
        nuke = 0
    elif h - 1 <= x <= h:
        res += g
        break
else:
    if x > 0:
        res += x - 1

print(res)

Submission status: Wrong Answer

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

B = [1, 1]
P = [3]
for i in range(2, N+1):
    # make B set
    C = []
    C.append(1 + B[0])
    for b in B:
        C.append(b)
    for b in B:
        C.append(b)
    C.append(1+ B[-1])
    B = C
    #print('B' + str(i), B)

Y = 0 # パティの数
# Xは残りの食べる層

for i, b in enumerate(B):
    if X <= 0: break
    else:
        X = X - b
        if i % 2 == 1:
            X = X - 3
            Y += max(min(X, 3), 0)
        else:
            X = X - 1
            Y += max(min(X, 1), 0)

print(Y)

Submission status: Wrong Answer

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

B = [1, 1]
P = [3]
for i in range(2, N+1):
    # make B set
    C = []
    C.append(1 + B[0])
    for b in B:
        C.append(b)
    for b in B:
        C.append(b)
    C.append(1+ B[-1])
    B = C
    #print('B' + str(i), B)

Y = 0 # パティの数
# Xは残りの食べる層

for i, b in enumerate(B):
    if X <= 0: break
    else:
        X = X - b
        if i % 2 == 1:
            X = X - 3
            Y += max(min(X, 3), 0)
        else:
            X = X - 1
            Y += max(min(X, 3), 0)

print(Y)

Submission status: Wrong Answer

Solution code:
def burg(n):
	b = {0:'P'}
	ps = {0:1}
	p_count = 1
	for i in range(1,n+1):
		# b[i] = 'B'+b[i-1]+'P'+b[i-1]+'B'
		ps[i] = ps[i-1]*2 + 1
	return ps[n]

l = input().split(' ')
n,x = int(l[0]),int(l[1])

print(burg(n))

Submission status: Wrong Answer

Solution code:
class Burg:
    def __init__(self):
        self.lv = [2**(i+1) - 1 for i in range(51)]

    def make_burg(self, n, m):
        if n == 0:
            return 1, m - 1
        num = 4 * 2**n - 3
        if num <= m:
            return self.lv[n], m - num
        if m <= 1:
            return 0, 0
        a, b = self.make_burg(n - 1, m - 1)
        if b <= 1:
            return a + b, 0
        c, d = self.make_burg(n - 1, b - 1)
        return a + c + 1, d - 1

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

gen = Burg()
print(gen.make_burg(n, x)[0])