ZhenlongDai/ACPR huggingface dataset:
Problem: p03209
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,x = map(int, input().split())

pl = [1]
pa = [1]

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

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

print(largest(n,x))

Failing test case input:
7 32

Expected output:
15


Actual output:
13


Fixed submission (verdict: Accepted):
n,x = map(int, input().split())

pl = [1]
pa = [1]

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

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

print(largest(n,x))

Problem: p03209
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N, X = [int(x) for x in input().split()]
h = [1]
b = [1]
for i in range(N):
    h.append(3 + h[i] * 2)
    b.append(1 + b[i] * 2)
def rec(n: int, x: int):
    if (n == 0):
        return 1 if x == 1 else 0
    mid = 1 + h[n-1] + 1
    if (x < mid):
        return rec(n-1, x-1)
    if (x == mid):
        return b[n-1] + 1
    if (mid < x):
        return b[n-1] + 1 + rec(n-1, x-mid)
print(rec(N, X))


Failing test case input:
6 32

Expected output:
15


Actual output:
14


Fixed submission (verdict: Accepted):
N, X = [int(x) for x in input().split()]
h = [1]
b = [1]
for i in range(N):
    h.append(3 + h[i] * 2)
    b.append(1 + b[i] * 2)
def rec(n: int, x: int):
    if (n == 0):
        return 0 if x <= 0 else 1
    mid = 1 + h[n-1] + 1
    if (x < mid):
        return rec(n-1, x-1)
    if (x == mid):
        return b[n-1] + 1
    if (mid < x):
        return b[n-1] + 1 + rec(n-1, x-mid)
print(rec(N, X))

Problem: p03209
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N, X = map(int, input().split())
a, p = [1], [1]
for i in range(N):
    a.append(a[i] * 2 + 3)
    p.append(a[i] * 2 + 1)

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

print(f(N,X))


Failing test case input:
61 4321098765432109

Expected output:
2160549382716050


Actual output:
4321098765431998


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

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

print(f(N,X))
Problem: p03209
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,x=map(int,input().split())
a,p=[1],[1]
for i in range(n):
  a.append(a[-1]*2+3)
  p.append(p[-1]*2+1)
def f(n,x):
  if n==0:return+(x>0)
  elif x<=i+a[n-1]:return f(n-1,x-1)
  else:return p[n-1]+1+f(n-1,x-2-a[n-1])
print(f(n,x))

Failing test case input:
10 30

Expected output:
12


Actual output:
9


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

Problem: p03209
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
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 rec(n, x, a, p):
    if n == 0:
        return 0
    elif x <= 1 + a[n - 1]:
        return rec(n - 1, x - 1, a, p)
    else:
        return p[n - 1] + 1 + rec(n - 1, x - 2 - a[n - 1], a, p)

ans = rec(n, x, a, p)
print(ans)

Failing test case input:
50 1069850374224873

Expected output:
534925187112439


Actual output:
534925187112438


Fixed submission (verdict: Accepted):
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 rec(n, x, a, p):
    if n == 0:
        return 0 if x <= 0 else 1
    elif x <= 1 + a[n - 1]:
        return rec(n - 1, x - 1, a, p)
    else:
        return p[n - 1] + 1 + rec(n - 1, x - 2 - a[n - 1], a, p)

ans = rec(n, x, a, p)
print(ans)

Problem: p03209
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, X = map(int, input().split())

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

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


print(f(N,X))



Failing test case input:
7 32

Expected output:
15


Actual output:
14


Fixed submission (verdict: Accepted):
N, X = map(int, input().split())

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

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


print(f(N,X))
Problem: p03209
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,x = map(int, input().split())

pl = [1]
pa = [1]

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

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

print(largest(n,x))

Failing test case input:
10 65

Expected output:
31


Actual output:
30


Fixed submission (verdict: Accepted):
n,x = map(int, input().split())

pl = [1]
pa = [1]

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

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

print(largest(n,x))

Problem: p03209
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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))

Failing test case input:
50 1069850374224873

Expected output:
534925187112439


Actual output:
534925187112438


Fixed submission (verdict: Accepted):
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 and x<=0:
    return 0
  elif n==0:
    return 1
  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))

Problem: p03209
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,x = map(int, input().split())

pl = [1]
pa = [1]

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

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

print(largest(n,x))


Failing test case input:
10 65

Expected output:
31


Actual output:
33


Fixed submission (verdict: Accepted):
n,x = map(int, input().split())

pl = [1]
pa = [1]

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

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

print(largest(n,x))
Problem: p03209
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, X = map(int, input().split())
burger  = [1] * (N+1)
patty = [1] * (N+1)
for i in range(1, N+1):
    burger[i] = burger[i-1] * 2 + 3
    patty[i] = patty[i-1] * 2 + 1


def func(level, x):
    if level == 0:
        return 0 if x <= 0 else 1
    if burger[level] + 1 <= x:
        return func(level-1, x-burger[level]-2) + patty[level] + 1
    else:
        return func(level-1, x-1)


print(func(N, X))


Failing test case input:
61 2749304303033015

Expected output:
1374652151516502


Actual output:
1374652151516501


Fixed submission (verdict: Accepted):
N, X = map(int, input().split())
burger  = [1] * N
patty = [1] * N
for i in range(1, N):
    burger[i] = burger[i-1] * 2 + 3
    patty[i] = patty[i-1] * 2 + 1


def func(level, x):
    if level == 0:
        return 0 if x <= 0 else 1
    if burger[level-1] + 1 < x:
        return func(level-1, x-burger[level-1]-2) + patty[level-1] + 1
    else:
        return func(level-1, x-1)


print(func(N, X))

Problem: p03209
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, X = map(int, input().split())

a, p = [1], [1]

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

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

print(f(N, X))

Failing test case input:
6 32

Expected output:
15


Actual output:
14


Fixed submission (verdict: Accepted):
N, X = map(int, input().split())

a, p = [1], [1]

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

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

print(f(N, X))

Problem: p03209
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n, x = map(int, input().split())

pate, slice = [1], [1]
for _ in range(n+1):
    pate.append(2 * pate[-1] + 1)
    slice.append(2 * slice[-1] + 3)

ans = 0
while n >= 0 and x > 0:
    if x >= slice[n - 1] + 2:
        ans += pate[n - 1] + 1
        x -= slice[n - 1] + 2
    elif x < slice[n - 1] + 2:
        x -= 1
    n -= 1
print(ans)


Failing test case input:
10 65

Expected output:
31


Actual output:
30


Fixed submission (verdict: Accepted):
n, x = map(int, input().split())

pate, slice = [1], [1]
for _ in range(n+1):
    pate.append(2 * pate[-1] + 1)
    slice.append(2 * slice[-1] + 3)

ans = 0
while n >= 0 and x > 0:
    if n == 0 and x > 0:
        ans += 1
        x -= 1
    elif x >= slice[n - 1] + 2:
        ans += pate[n - 1] + 1
        x -= slice[n - 1] + 2
    elif x < slice[n - 1] + 2:
        x -= 1
    n -= 1
print(ans)
Problem: p03209
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,x=map(int,input().split())
a=[(1,1)]
for _ in range(n):
  a+=[(a[-1][0]*2+3,a[-1][1]*2+1)]

s=0
for i,j in a[::-1]:
  x-=1
  if i<=x:
    x-=i;s+=j
    if x>=1:
      x-=1;s+=1

print(s)


Failing test case input:
6 28

Expected output:
14


Actual output:
13


Fixed submission (verdict: Accepted):
n,x=map(int,input().split())
a=[(1,1)]
for _ in range(n):
  a+=[(a[-1][0]*2+3,a[-1][1]*2+1)]

if a[-1][0] in (x,x-1):
  print(a[-1][1])
  exit()
a=a[:-1]
s=0
for k in range(1,len(a)*2+1):
  i,j = a[-k 
  x -= k % 2
  if i <= x:
    x-=i;s+=j
    if x>=1:
      x-=1;s+=1

print(s)

Problem: p03209
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
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 f(n,x):
    if n==1:
        return 1 if x==1 else 0
    if x<=a[n-1]+1:
        return f(n-1,x-1)
    return p[n-1]+f(n-1,x-a[n-1]-2)+1
print(f(N,X))

Failing test case input:
61 787102107885139

Expected output:
393551053942568


Actual output:
393551053942569


Fixed submission (verdict: Accepted):
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 f(n,x):
    if n==0:
        return 0 if x<=0 else 1
    if x<=a[n-1]+1:
        return f(n-1,x-1)
    return p[n-1]+f(n-1,x-a[n-1]-2)+1
print(f(N,X))

Problem: p03209
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
def main():
    n, x = map(int, input().split())

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

    ans = 0
    for _ in range(n):
        if x == 0:
            break
        if x >= pb[-2] + 2:
            x -= pb[-2] + 2
            ans += 1 + p[-2]
        else:
            x -= 1
        pb.pop(-1)
        p.pop(-1)

    if x == 1:
        ans += 1

    print(ans)

main()

Failing test case input:
7 32

Expected output:
15


Actual output:
14


Fixed submission (verdict: Accepted):
def main():
    n, x = map(int, input().split())

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

    ans = 0
    for _ in range(n):
        if x == 0:
            break
        if x >= pb[-2] + 2:
            x -= pb[-2] + 2
            ans += 1 + p[-2]
        else:
            x -= 1
        pb.pop(-1)
        p.pop(-1)

    if x >= 1:
        ans += 1

    print(ans)

main()
Problem: p03209
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,x = map(int,input().split())

a,p = [1],[1]

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

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

print(f(n,x))

Failing test case input:
50 1069850374224873

Expected output:
534925187112439


Actual output:
1929


Fixed submission (verdict: Accepted):
n,x = map(int,input().split())

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

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

print(f(n,x))

Problem: p03209
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,x=map(int,input().split())
a=[(1,1)]
for _ in range(n):
  a+=[(a[-1][0]*2+3,a[-1][1]*2+1)]

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

s=0
for i,j in a[::-1]:
  x-=1
  if i<=x:
    x-=i+1
    s+=j+1
print(s)



Failing test case input:
50 3396494817772502

Expected output:
1698247408886243


Actual output:
1698247408886242


Fixed submission (verdict: Accepted):
n,x=map(int,input().split())
a=[(1,1)]
for _ in range(n):
  a+=[(a[-1][0]*2+3,a[-1][1]*2+1)]

if a[-1][0] in (x,x-1):
  print(a[-1][1])
  exit()
a=a[:-1]
s=0
for k in range(1,len(a)*2+1):
  i,j = a[-k 
  x -= k % 2
  if i <= x:
    x-=i;s+=j
    if x>=1:
      x-=1;s+=1

print(s)

Problem: p03209
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,x=map(int,input().split())
a=[(1,1)]
for _ in range(n):
  a+=[(a[-1][0]*2+3,a[-1][1]*2+1)]

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

s=0
for i,j in a[::-1]:
  x-=1
  if i<=x:
    x-=i+1
    s+=j+1
  if x>=1:
    x-=1
    s+=1
print(s)

Failing test case input:
50 3396494817772502

Expected output:
1698247408886243


Actual output:
1698247408886268


Fixed submission (verdict: Accepted):
n,x=map(int,input().split())
a=[(1,1)]
for _ in range(n):
  a+=[(a[-1][0]*2+3,a[-1][1]*2+1)]

if a[-1][0] in (x,x-1):
  print(a[-1][1])
  exit()
a=a[:-1]
s=0
for k in range(1,len(a)*2+1):
  i,j = a[-k 
  x -= k % 2
  if i <= x:
    x-=i;s+=j
    if x>=1:
      x-=1;s+=1

print(s)

Problem: p03209
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

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

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

Failing test case input:
79 1069850374224873

Expected output:
534925187112424


Actual output:
562949953421311


Fixed submission (verdict: Accepted):

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

def f(n, x):
    if n == 0:
        return 0 if x <= 0 else 1
    elif x <= 1 + a[n-1]:
        return f(n-1, x-1)
    else:
        return p[n-1] + 1 + f(n-1, x-2-a[n-1])
print(f(N, X))
Problem: p03209
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a = [1]
p = [1]
N,X = map(int,input().split())
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 x <= a[n-1]+1:
        return f(n-1,x-1)
    else:
        return f(n-1,x-2-a[n-1])+p[n-1]+1
print(f(N,X))

Failing test case input:
8 19

Expected output:
7


Actual output:
6


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

Problem: p03209
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,x=map(int,input().split())
a=[(1,1)]
for _ in range(n):
  a+=[(a[-1][0]*2+3,a[-1][1]*2+1)]

if a[-1][0]==x:
  print(a[-1][1])
  exit()
if a[-1][0]==x-1:
  print(a[-1][1]-1)
  exit()
a=a[:-1]
 
s=0
for i,j in a[::-1]:
  x-=1
  if i<=x:
    x-=i;s+=j
    if x>=1:
      x-=1;s+=1
print(s)

Failing test case input:
6 30

Expected output:
15


Actual output:
14


Fixed submission (verdict: Accepted):
n,x=map(int,input().split())
a=[(1,1)]
for _ in range(n):
  a+=[(a[-1][0]*2+3,a[-1][1]*2+1)]

if a[-1][0] in (x,x-1):
  print(a[-1][1])
  exit()
a=a[:-1]
s=0
for k in range(1,len(a)*2+1):
  i,j = a[-k 
  x -= k % 2
  if i <= x:
    x-=i;s+=j
    if x>=1:
      x-=1;s+=1

print(s)

Problem: p03209
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, X = (int(i) for i in input().split())  
L = [1]
P = [1]

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

def count(x,n):
  if n == 0:
    return 0 if x <= 0 else 1
  elif x <= L[n-1] + 2:
    return count(x-1, n-1)
  else:
    return P[n-1] + 1 + count(x-(L[n-1]+2),n-1)


print(count(X, N))

Failing test case input:
61 1240793510486497

Expected output:
620396755243242


Actual output:
620396755243241


Fixed submission (verdict: Accepted):
N, X = (int(i) for i in input().split())  
L = [1]
P = [1]

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

def count(x,n):
  if n == 0:
    return 0 if x <= 0 else 1
  elif x <= L[n-1] + 1:
    return count(x-1, n-1)
  else:
    return P[n-1] + 1 + count(x-(L[n-1]+2),n-1)


print(count(X, N))
Problem: p03209
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, x = map(int, input().split())
def get_len(lv):
  m = 1
  for i in range(lv):
    m = m * 2 + 5
  return m  
def count_p(lv, p):
  if p == 0:return 0
  elif lv == 0:return 1
  m = get_len(lv)
  if p > (m-1)/2:
    return (m-1)/2 + 1 - count_p(lv, m-p)
  else:
    return count_p(lv-1,p-1)
print(int(count_p(n, x)))

Failing test case input:
79 1069850374224873

Expected output:
534925187112424


Actual output:
534925187112420


Fixed submission (verdict: Accepted):
n, x = map(int, input().split())
def get_len(lv):
  m = 1
  for i in range(lv):
    m = m * 2 + 3
  return m  
def count_p(lv, p):
  if p <= lv:return 0
  elif lv == 0:return 1
  m = get_len(lv)
  if p > (m-1)/2:
    return (m-1)/2 + 1 - count_p(lv, m-p)
  else:
    return count_p(lv-1,p-1)
print(int(count_p(n, x)))

Problem: p03209
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, x = map(int, input().split())
p, q = [1] + [0] * n, [1] + [0] * n

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

def rec(i, x):
    if i == 0: return 1 if x >= 1 else 0
    mid = q[i] 
    if x < mid:
        return rec(i-1, x-1)
    else:
        return p[i-1] + 1 + rec(i-1, x-mid-1)

print(rec(n, x))


Failing test case input:
61 787102107885139

Expected output:
393551053942568


Actual output:
196775526971292


Fixed submission (verdict: Accepted):
n, x = map(int, input().split())
p, q = [1] + [0] * n, [1] + [0] * n

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

def rec(i, x):
    if i == 0: return 1 if x >= 1 else 0
    mid = q[i-1] + 2
    if x < mid:
        return rec(i-1, x-1)
    else:
        return p[i-1] + 1 + rec(i-1, x-mid)

print(rec(n, x))

Problem: p03209
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,x=map(int,input().split())
a=[1]
p=[1]
for i in range(n-1):
    a.append(a[i]*2+3)
    p.append(p[i]*2+1)
def f(n,x):
  if n==0 and x==1:
    return 1
  elif 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]+1+f(n-1,x-2-a[n-1])
print(f(n,x))

Failing test case input:
6 30

Expected output:
15


Actual output:
14


Fixed submission (verdict: Accepted):
N,X=map(int,input().split())
a,p=[1],[1]
for i in range(N):
    a.append(a[i]*2+3)
    p.append(p[i]*2+1)
def f(n,x):
    if n==0:return 0 if x<=0 else 1
    elif x<=1+a[n-1]:return f(n-1,x-1)
    else:return p[n-1]+1+f(n-1,x-2-a[n-1])
print(f(N,X))
Problem: p03209
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,x=map(int,input().split())
a=[(1,1)]
for _ in range(n):
  a+=[(a[-1][0]*2+3,a[-1][1]*2+1)]

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

s=0
for i,j in a[::-1]:
  x-=1
  if i<=x:
    x-=i;s+=j
    if x>=1:
      x-=1;s+=1
print(s)

Failing test case input:
10 65

Expected output:
31


Actual output:
30


Fixed submission (verdict: Accepted):
n,x=map(int,input().split())
a=[(1,1)]
for _ in range(n):
  a+=[(a[-1][0]*2+3,a[-1][1]*2+1)]

if a[-1][0] in (x,x-1):
  print(a[-1][1])
  exit()
a=a[:-1]
s=0
for k in range(1,len(a)*2+1):
  i,j = a[-k 
  x -= k % 2
  if i <= x:
    x-=i;s+=j
    if x>=1:
      x-=1;s+=1

print(s)

Problem: p03209
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n,x = map(int, input().split())

b = [[1,1]]

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

print(b)

ans = 0
for i in range(len(b)):
    if x >= b[-1-i][0]:
        x -= b[-1-i][0]
        ans += b[-1-i][1]
        if x > 0:
            x-=1
            ans += 1
        if x>=b[-1-i][0]:
            x -= b[-1 - i][0]
            ans += b[-1 - i][1]
            break
    x-=1
    if x<=0:
        break

print(ans)

Failing test case input:
33 -1

Expected output:
0


Actual output:
[[1, 1], [5, 3], [13, 7], [29, 15], [61, 31], [125, 63], [253, 127], [509, 255], [1021, 511], [2045, 1023], [4093, 2047], [8189, 4095], [16381, 8191], [32765, 16383], [65533, 32767], [131069, 65535], [262141, 131071], [524285, 262143], [1048573, 524287], [2097149, 1048575], [4194301, 2097151], [8388605, 4194303], [16777213, 8388607], [33554429, 16777215], [67108861, 33554431], [134217725, 67108863], [268435453, 134217727], [536870909, 268435455], [1073741821, 536870911], [2147483645, 1073741823], [4294967293, 2147483647], [8589934589, 4294967295], [17179869181, 8589934591], [34359738365, 17179869183]]
0


Fixed submission (verdict: Accepted):
n,x = map(int, input().split())

b = [[1,1]]

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

ans = 0
for i in range(len(b)):
    if x >= b[-1-i][0]:
        x -= b[-1-i][0]
        ans += b[-1-i][1]
        if x > 0:
            x-=1
            ans += 1
        if x>=b[-1-i][0]:
            x -= b[-1 - i][0]
            ans += b[-1 - i][1]
            break
    x-=1
    if x<=0:
        break

print(ans)
Problem: p03209
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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 N == 0:
        return 0 if X <= 0 else 1
    elif X <= 1+a[N-1]:
        return f(N-1, X-1)
    else:
        return p[N-1] + f(N-1, X-2-a[N-1])
print(f(N,X))

Failing test case input:
7 32

Expected output:
15


Actual output:
12


Fixed submission (verdict: Accepted):
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 N == 0:
        return 0 if X <= 0 else 1
    elif 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 <= 2+2*a[N-1]:
        return p[N-1] + 1 + f(N-1, X-2-a[N-1])
    elif X == 3+2*a[N-1]:
        return 2*p[N-1] +1

print(f(N,X))

Problem: p03209
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,x = map(int, input().split())

pl = [1]
pa = [1]

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

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

print(largest(n,x))

Failing test case input:
6 30

Expected output:
15


Actual output:
16


Fixed submission (verdict: Accepted):
n,x = map(int, input().split())

pl = [1]
pa = [1]

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

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

print(largest(n,x))

Problem: p03209
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, X = map(int, input().split())

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

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

print(f(N, X))

Failing test case input:
6 33

Expected output:
16


Actual output:
8


Fixed submission (verdict: Accepted):
N, X = map(int, input().split())

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

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

print(f(N, X))
Problem: p03209
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,x=map(int,input().split())


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

def cnt(n,x):
    
    if n==0:
        return 1 if x>=1 else 0

    elif x<=1+a[-2]:
        return cnt(n-1,x-1)

    elif 2+a[-2]<=x:
        return cnt(n-1,x-(a[-2]+2))+p[-2]+1

print(cnt(n,x))

Failing test case input:
61 1240793510486497

Expected output:
620396755243242


Actual output:
1


Fixed submission (verdict: Accepted):
n,x=map(int,input().split())


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

def cnt(n,x):
    
    if n==0:
        return 1 if x>=1 else 0

    elif x<=1+a[n-1]:
        return cnt(n-1,x-1)

    elif 2+a[n-1]<=x:
        return cnt(n-1,x-(a[n-1]+2))+p[n-1]+1

print(cnt(n,x))

Problem: p03209
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,X=map(int,input().split())
ans=0
def rec(x,n):
    global ans
    if n==0:
        if x==1:
            ans+=1
    elif x>2**(n+1)-2:
        ans+=(2**n-1+1)
        rec(x-(2**(n+1)-1),n-1)
    else:
        rec(x-1,n-1)

rec(X,N)
print(ans)


Failing test case input:
50 3396494817772502

Expected output:
1698247408886243


Actual output:
1698247408886242


Fixed submission (verdict: Accepted):
N,X=map(int,input().split())
ans=0
def rec(x,n):
    global ans
    if n==0:
        if x>=1:
            ans+=1
    elif x>2**(n+1)-2:
        ans+=(2**n-1+1)
        rec(x-(2**(n+1)-1),n-1)
    else:
        rec(x-1,n-1)

rec(X,N)
print(ans)

Problem: p03209
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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))

Failing test case input:
6 32

Expected output:
15


Actual output:
14


Fixed submission (verdict: Accepted):
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 and x<=0:
    return 0
  elif n==0:
    return 1
  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))
Problem: p03209
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, X = map(int, input().split())
burger  = [1] * (N+1)
patty = [1] * (N+1)
for i in range(1, N+1):
    burger[i] = burger[i-1] * 2 + 3
    patty[i] = patty[i-1] * 2 + 1


def func(level, x):
    if level == 0 or x == 1:
        return 0
    if burger[level-1] + 1 <= x:
        return func(level-1, x-burger[level-1]-2) + patty[level-1] + 1
    else:
        return func(level-1, x-1)


print(func(N, X))


Failing test case input:
7 32

Expected output:
15


Actual output:
14


Fixed submission (verdict: Accepted):
N, X = map(int, input().split())
burger  = [1] * N
patty = [1] * N
for i in range(1, N):
    burger[i] = burger[i-1] * 2 + 3
    patty[i] = patty[i-1] * 2 + 1


def func(level, x):
    if level == 0:
        return 0 if x <= 0 else 1
    if burger[level-1] + 1 < x:
        return func(level-1, x-burger[level-1]-2) + patty[level-1] + 1
    else:
        return func(level-1, x-1)


print(func(N, X))

Problem: p03209
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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 f(N, X):
	if N == 0:
		return 0 if X <= 0 else 1
	elif 1 <= X <= a[N-1]+1:
		return f(N-1, X-1)
	
	
	
	
	
	
	else:
		return f(N-1, X-2-a[N-1]) + p[N-1] + 1

print(f(N, X))


Failing test case input:
22 8

Expected output:
0


Actual output:
32766


Fixed submission (verdict: Accepted):
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 f(N, X):
	if N == 0:
		return 0 if X <= 0 else 1
	elif X <= a[N-1]+1:
		return f(N-1, X-1)
	elif X == a[N-1]+2:
		return p[N-1] + 1
	elif a[N-1]+3 <= X <= 2*a[N-1]+2:
		return f(N-1, X-2-a[N-1]) + p[N-1] + 1
	else:
		return p[N]

print(f(N, X))

Problem: p03209
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,x = map(int,input().split())

a,p = [1],[1]



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

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

        else:
            return 1

    elif X <= 1 + a[n -1]:
        return f(N -1,X-1)

    else:
        return p[N-1] + 1 + f(N -1, X-2-a[N-1])

print(f(n,x))

Failing test case input:
6 33

Expected output:
16


Actual output:
1


Fixed submission (verdict: Accepted):
n,x = map(int,input().split())

a,p = [1],[1]



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

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

        else:
            return 1

    elif X <= 1 + a[N-1]:
        return f(N -1,X-1)

    else:
        return p[N-1] + 1 + f(N -1, X-2-a[N-1])

print(f(n,x))
Problem: p03209
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,x=map(int,input().split())
a=[1]
p=[1]
for i in range(n-1):
    a.append(a[i]*2+3)
    p.append(p[i]*2+1)
def f(n,x):
  if n==0 or x<=1:
    return 0
  elif x<=1+a[n-1]:
    return f(n-1,x-1)
  else:
    return p[n-1]+1+f(n-1,x-2-a[n-1])
print(f(n,x))

Failing test case input:
7 32

Expected output:
15


Actual output:
14


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

Problem: p03209
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, X = map(int, input().split())
burger  = [1] * (N+1)
patty = [1] * (N+1)
for i in range(1, N+1):
    burger[i] = burger[i-1] * 2 + 3
    patty[i] = patty[i-1] * 2 + 1


def func(level, x):
    if level == 0:
        return 0
    if burger[level] + 1 <= x:
        return func(level-1, x-burger[level]-2) + patty[level] + 1
    else:
        return func(level-1, x-1)


print(func(N, X))


Failing test case input:
50 1069850374224873

Expected output:
534925187112439


Actual output:
534925187112436


Fixed submission (verdict: Accepted):
N, X = map(int, input().split())
burger  = [1] * N
patty = [1] * N
for i in range(1, N):
    burger[i] = burger[i-1] * 2 + 3
    patty[i] = patty[i-1] * 2 + 1


def func(level, x):
    if level == 0:
        return 0 if x <= 0 else 1
    if burger[level-1] + 1 < x:
        return func(level-1, x-burger[level-1]-2) + patty[level-1] + 1
    else:
        return func(level-1, x-1)


print(func(N, X))

Problem: p03209
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,x = map(int,input().split())
ans =0
while x > 0:
    if x ==2**(n+2)-3:
        x-=1
    elif x == 1:
        break
    elif x >=2**(n+1)-1:
        ans += 2**n
        x -=2**(n+1)-1
        n -=1
    elif x == 2**(n+1)-2:
        ans += 2**n-1
        break
    else:
        n -=1
        x -=1
print(ans)

Failing test case input:
7 32

Expected output:
15


Actual output:
14


Fixed submission (verdict: Accepted):
n,x = map(int,input().split())
ans =0
while x > 0:
    if n==0:
        ans +=1
        break
    elif x == 1:
        break
    elif x >=2**(n+1)-1:
        ans += 2**n
        x -=2**(n+1)-1
        n -=1
    elif x == 2**(n+1)-2:
        ans += 2**n-1
        print(ans)
        exit()
    else:
        n -=1
        x -=1
print(ans)
Problem: p03209
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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 f(n,x):
  if n==0:
    if x==1:
      return 1
    else:
      return 0
  elif x<=a[n-1]+1:
    return f(n-1,x-1)
  else:
    return p[n-1]+1+f(n-1,x-2-a[n-1])
print(f(N,X))

Failing test case input:
10 65

Expected output:
31


Actual output:
30


Fixed submission (verdict: Accepted):
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 f(n,x):
  if n==0:
    if x<1:
      return 0
    else:
      return 1
  elif x<=a[n-1]+1:
    return f(n-1,x-1)
  else:
    return p[n-1]+1+f(n-1,x-2-a[n-1])
print(f(N,X))

Problem: p03209
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,X = map(int,input().split())

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

ans = 0
for i in reversed(range(N)):
    if X == s[i]+2:
        ans += p[i]+1
        break
    elif X < s[i]+2:
        X -= 1
    else:
        X -= (s[i]+2)
        ans += p[i]+1
print(ans)

Failing test case input:
7 32

Expected output:
15


Actual output:
14


Fixed submission (verdict: Accepted):
N,X = map(int,input().split())

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

ans = 0
for i in reversed(range(N)):
    if i > 0:
        if X == s[i]+2:
            ans += p[i]+1
            break
        elif X < s[i]+2:
            X -= 1
        else:
            X -= (s[i]+2)
            ans += p[i]+1
    else:
        ans += max(0,min(3, X-1))
print(ans)

Problem: p03209
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
from collections import deque
stdin = sys.stdin

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

n, x = na()
bg = "P"
an = 2 ** (n+2) - 3
bn = 2 ** (n+1) - 1
if an > x:
    print(bn)
else:
    for i in range(n):
        bg = "B" + bg + "P" + bg + "B"
        if len(bg) > x:
            bg = bg[:x]
    print(bg[:x].count("P"))

Failing test case input:
5 19

Expected output:
8


Actual output:
63


Fixed submission (verdict: Accepted):
import sys
from collections import deque
stdin = sys.stdin

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

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

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

print(f(n,x))
Problem: p03209
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from functools import lru_cache
@lru_cache(maxsize=None)
def b(n):
    if n<1:return 1
    return b(n-1)*2+3
@lru_cache(maxsize=None)
def p(n):
    if n<1:return 1
    return p(n-1)*2+1
def solve(n,x):
    if n<1:return int(x>0)
    if x<=b(n-1):return(solve(n-1,x-1))
    return p(n-1)+solve(n-1,x-b(n-1)-2)+1
print(solve(*map(int,input().split())))

Failing test case input:
4 38

Expected output:
19


Actual output:
20


Fixed submission (verdict: Accepted):
from functools import lru_cache
@lru_cache(maxsize=None)
def b(n):
    if n<1:return 1
    return b(n-1)*2+3
@lru_cache(maxsize=None)
def p(n):
    if n<1:return 1
    return p(n-1)*2+1
def solve(n,x):
    if n<1:return int(x>0)
    if x-2<b(n-1):return(solve(n-1,x-1))
    return p(n-1)+solve(n-1,x-b(n-1)-2)+1
print(solve(*map(int,input().split())))

Problem: p03209
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,x=map(int,input().split())
a=[1]
p=[1]
for i in range(n-1):
    a.append(a[i]*2+3)
    p.append(p[i]*2+1)
def f(n,x):
  if n==0 and x==1:
    return 1
  elif n==0:
    return 0
  elif x<=1+a[n-1]:
    return f(n-1,x-1)
  else:
    return p[n-1]+1+f(n-1,x-2-a[n-1])
print(f(n,x))

Failing test case input:
50 1069850374224873

Expected output:
534925187112439


Actual output:
534925187112438


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

Problem: p03209
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def patty(n,x):
  if n == 0:
    if x == 0:
      return 0
    else: 
      return 1
  elif x <= 1 + a[n-1]:
    return patty(n-1, x-1)
  else:
    return p[n-1] + 1 + patty(n-1, x-2-a[n-1])

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)
ans = patty(n,x)
print(ans)

Failing test case input:
28 -1

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
def patty(n,x):
  if n == 0:
    if x <= 0:
      return 0
    else: 
      return 1
  elif x <= 1 + a[n-1]:
    return patty(n-1, x-1)
  else:
    return p[n-1] + 1 + patty(n-1, x-2-a[n-1])

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)
ans = patty(n,x)
print(ans)
Problem: p03209
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
N,X = list(map(int, input().split()))
cnt = 0
for i in range(N, 0, -1):
  t = math.pow(2, i + 1) - 2
  if X > t:
    cnt += t / 2
    X -= t
    if X > 1:
      cnt += 1
      X -= 1
    elif X == 1:
      cnt += 1
      break
    else:
      break
  else:
    if X > 1:
      X -= 1
    else:
      break
print(int(cnt))

Failing test case input:
10 65

Expected output:
31


Actual output:
30


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

Problem: p03209
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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))

Failing test case input:
10 65

Expected output:
31


Actual output:
30


Fixed submission (verdict: Accepted):
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 and x<=0:
    return 0
  elif n==0:
    return 1
  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))

Problem: p03209
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,x=map(int,input().split())
a=[(1,1)]
for _ in range(n):
  a+=[(a[-1][0]*2+3,a[-1][1]*2+1)]

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

s=0
for i,j in a[::-1]:
  x-=1
  if i<=x:
    x-=i
    s+=j
    if x>=1:
      x-=1
      s+=1
print(s)

Failing test case input:
6 30

Expected output:
15


Actual output:
14


Fixed submission (verdict: Accepted):
n,x=map(int,input().split())
a=[(1,1)]
for _ in range(n):
  a+=[(a[-1][0]*2+3,a[-1][1]*2+1)]

if a[-1][0] in (x,x-1):
  print(a[-1][1])
  exit()
a=a[:-1]
s=0
for k in range(1,len(a)*2+1):
  i,j = a[-k 
  x -= k % 2
  if i <= x:
    x-=i;s+=j
    if x>=1:
      x-=1;s+=1

print(s)

Problem: p03209
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n,x=map(int,input().split())
a=[1]
p=[1]
for i in range(n):
    a.append(a[i-1]*2+3)
    p.append(p[i-1]*2+1)


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

print(f(n,x))


Failing test case input:
6 32

Expected output:
15


Actual output:
16


Fixed submission (verdict: Accepted):
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 f(n,x):
    if n==0:
        if x<=0:
            return 0
        else:
            return 1
    elif x<=1+a[n-1]:
        return f(n-1,x-1)
    else:
        return p[n-1]+1+f(n-1,x-2-a[n-1])

print(f(n,x))
Problem: p03209
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, X = map(int, input().split())

def rep(N,X):
    if N == 1:
        if X == 1 or X == 5:
            return(0)
        else:
            return(X-1)
    elif X == 1:
        return(0)
    else:
        n = 2**(N+2)-3
        a = n
        p = 2**N-1
        if a < -1:
            return(rep(N-1, abs(a)) + p + 1)
        elif a == -1 or a == 0 or a == 1:
            return(p + 1)
        else:
            return(rep(N-1, X-1))
print(rep(N,X))

Failing test case input:
5 19

Expected output:
8


Actual output:
14


Fixed submission (verdict: Accepted):
N, X = map(int, input().split())

def rep(N,X):
    if N == 1:
        if X == 1:
            return(0)
        elif X == 5:
            return(3)
        else:
            return(X-1)
    elif X == 1:
        return(0)
    else:
        n = 2**(N+2)-3
        p = 2**N-1 
        if X <= n
            return(rep(N-1, X-1))
        elif X == n
            return(p + 1)
        else:
            if n-1 == X-1:
                return(rep(N-1, X-1-n
            else:
                return(rep(N-1, X-1-n
print(rep(N,X))

Problem: p03209
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n,x = map(int,input().split())
ans = 0
i = n
while i > 1:
    c = 2**(i+1) - 3
    num_p = 2**i - 1
    
    if 2*c + 3 == x:
        ans += 2*num_p + 1
        break
    elif c + 2 == x:
        ans += num_p + 1
        break
    elif 1 == x:
        break
    
    elif 2 + c <= x:
        x -= 2 + c
        ans += num_p + 1
    else:
        x -= 1
    
    i -= 1

print(ans)

Failing test case input:
61 2749304303033015

Expected output:
1374652151516502


Actual output:
1374652151516500


Fixed submission (verdict: Accepted):
n,x = map(int,input().split())
ans = 0
i = n
while i >= 0:
    c = 2**(i+1) - 3
    num_p = 2**i - 1
    
    if 2*c + 3 == x:
        ans += 2*num_p + 1
        break
    elif c + 2 == x:
        ans += num_p + 1
        break
    elif 1 == x:
        break
    
    elif 2 + c <= x:
        x -= 2 + c
        ans += num_p + 1
    else:
        x -= 1
    
    i -= 1

print(ans)

Problem: p03209
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, x = map(int, input().split())

a, p = [1], [1]

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

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

print(f(n, x))

Failing test case input:
50 3396494817772502

Expected output:
1698247408886243


Actual output:
1698247408886240


Fixed submission (verdict: Accepted):
n, x = map(int, input().split())

a, p = [1], [1]

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

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

print(f(n, x))
Problem: p03209
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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))

Failing test case input:
6 41

Expected output:
20


Actual output:
0


Fixed submission (verdict: Accepted):
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))

Problem: p03209
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,x = map(int,input().split())
ans =0
while x > 0:
    if x ==2**(n+2)-3:
        x-=1
    elif x == 1:
        break
    elif x >=2**(n+1)-1:
        ans += 2**n
        x -=2**(n+1)-1
        n -=1
    elif x == 2**(n+1)-2:
        ans += 2**n-1
        print(ans)
        exit()
    else:
        n -=1
        x -=1
print(ans)

Failing test case input:
10 65

Expected output:
31


Actual output:
30


Fixed submission (verdict: Accepted):
n,x = map(int,input().split())
ans =0
while x > 0:
    if n==0:
        ans +=1
        break
    elif x == 1:
        break
    elif x >=2**(n+1)-1:
        ans += 2**n
        x -=2**(n+1)-1
        n -=1
    elif x == 2**(n+1)-2:
        ans += 2**n-1
        print(ans)
        exit()
    else:
        n -=1
        x -=1
print(ans)

Problem: p03209
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n,x=map(int,input().split())
patty=[1]
barger=[1]
ans=0
for i in range(n):
  patty.append(2*patty[-1]+1)
  barger.append(2*barger[-1]+3)
i=n
count=0
mid=True
while x>0:
  count+=1
  for _ in range(n):
    if x>=barger[i]:
      x-=barger[i]
      ans+=patty[i]
      if x>0 and mid:
        ans+=1
        mid=False
      else:
        mid=True
      break
    x-=1
    i-=1
print(ans)

Failing test case input:
4 20

Expected output:
10


Actual output:
12


Fixed submission (verdict: Accepted):
n,x=map(int,input().split())
patty=[1]
barger=[1]
ans=0
for i in range(n):
  patty.append(2*patty[-1]+1)
  barger.append(2*barger[-1]+3)
i=n
while x>0:
  for _ in range(n):
    if x>=barger[i]:
      x-=barger[i]
      ans+=patty[i]
      if x>0:
        ans+=1
        x-=1
      break
    i-=1
    x-=1
print(ans)