Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
mod = 10**9+7

dp = [[0 for j in range(13)] for i in range(len(S)+1)]
dp[0][0] = 1
for i in range(1, len(S)+1):
    s = S[i-1]

    if s == "?":
        for s in range(10):
            for j in range(13):
                dp[i][(10 * j + s) % 13] += dp[i - 1][j]
                dp[i][(10 * j + s) % 13] %= mod
    else:
        s = int(s)
        for j in range(13):
            dp[i][(10*j+s)%13] += dp[i-1][j]
            dp[i][(10*j+s)%13] %= mod
print(dp[len(S)][5])

Fixed submission:
S = input()
mod = 10**9+7

dp = [[0 for j in range(13)] for i in range(len(S)+1)]
dp[0][0] = 1
for i in range(1, len(S)+1):
    s = S[i-1]

    if s == "?":
        for s in range(10):
            for j in range(13):
                dp[i][(10 * j + s) % 13] += dp[i - 1][j]
                dp[i][(10 * j + s) % 13] %= mod
    else:
        s = int(s)
        for j in range(13):
            dp[i][(10*j+s)%13] += dp[i-1][j]
            dp[i][(10*j+s)%13] %= mod
print(dp[len(S)][5])
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

N = int(input())
a_list = [int(input()) for i in range(N)]

colors = []
colors.append(a_list[0])
for i in range(1, N):
    a = a_list[i]
    idx = bisect.bisect_left(colors, a)
    if idx == 0:
        colors.insert(0, a)
    else:
        colors[idx-1] = a

print(len(colors))

Fixed submission:
import bisect
from collections import deque

N = int(input())
a_list = [int(input()) for i in range(N)]

colors = deque([])
colors.append(a_list[0])
for i in range(1, N):
    a = a_list[i]
    idx = bisect.bisect_left(colors, a)
    if idx == 0:
        colors.appendleft(a)
    else:
        colors[idx-1] = a

print(len(colors))

Buggy python submission (verdict: Time Limit Exceeded):
import bisect

N = int(input())
a_list = [int(input()) for i in range(N)]

colors = []
colors.append(a_list[0])
for i in range(1, N):
    a = a_list[i]
    idx = bisect.bisect_left(colors, a)
    if idx == 0:
        colors.insert(0, a)
    else:
        colors[idx-1] = a

print(len(colors))

Fixed submission:
import bisect
from collections import deque

N = int(input())
a_list = [int(input()) for i in range(N)]

colors = deque([])
colors.append(a_list[0])
for i in range(1, N):
    a = a_list[i]
    idx = bisect.bisect_left(colors, a)
    if idx == 0:
        colors.appendleft(a)
    else:
        colors[idx-1] = a

print(len(colors))
Buggy python submission (verdict: Time Limit Exceeded):
L, R = map(int, input().split())
mod = 2019
nums = list(set([i % 2019for i in range(L, R+1)]))

res = []
for i in range(len(nums)):
    for j in range(i+1, len(nums)):
       res.append((nums[i]*nums[j])%mod)
print(min(res))



Fixed submission:
L, R = map(int, input().split())
mod = 2019
if (R-L+1) >= 2019:
    nums = [i for i in range(2019)]
else:
    nums = list(set([i % 2019for i in range(L, R+1)]))

res = []
for i in range(len(nums)):
    for j in range(i+1, len(nums)):
       res.append((nums[i]*nums[j])%mod)
print(min(res))
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
MOD = 10**9+7
red_num = n - k
blue_num = k

def prepare(n, MOD):
    """
    nCr mod MOD
    n!/r!*(n-r)! → facts(n)*invs(r)*invs(n-r)
    :param n:
    :param MOD:
    :return:
    """
    facts = [1]*(n+1)
    for i in range(1, n+1):
        facts[i] = facts[i-1]*i%MOD
    invs = [1]*(n+1)
    _invs = [1]*(n+1)
    invs[n] = pow(facts[n], MOD-2, MOD)
    for i in range(0, n)[::-1]:
        invs[i] = invs[i+1] * (i+1) % MOD
    return facts, invs

for i in range(1, k+1):
    facts1, inves1 = prepare(red_num+1, MOD)
    facts2, inves2 = prepare(k-1, MOD)
    a = facts1[red_num+1]*inves1[i]*inves1[red_num+1-i]%MOD
    b = facts2[k-1]*inves2[i-1]*inves2[k-i]%MOD

    print(a*b%MOD)
    



Fixed submission:
n, k = map(int, input().split())
MOD = 10**9+7
red_num = n - k
blue_num = k

def prepare(n, MOD):
    """
    nCr mod MOD
    n!/r!/(n-r)! → facts(n)*invs(r)*invs(n-r)
    :param n:
    :param MOD:
    :return:
    """
    facts = [1]*(n+1)
    for i in range(1, n+1):
        facts[i] = facts[i-1]*i%MOD
    invs = [1]*(n+1)
    _invs = [1]*(n+1)
    invs[n] = pow(facts[n], MOD-2, MOD)
    for i in range(0, n)[::-1]:
        invs[i] = invs[i+1] * (i+1) % MOD
    return facts, invs

for i in range(1, k+1):
    if red_num+1 < i:
        print(0)
        continue
    facts1, inves1 = prepare(red_num+1, MOD)
    facts2, inves2 = prepare(k-1, MOD)
    a = facts1[red_num+1]*inves1[i]*inves1[red_num+1-i]%MOD
    b = facts2[k-1]*inves2[i-1]*inves2[k-i]%MOD

    print(a*b%MOD)
Buggy python submission (verdict: Runtime Error):
N = int(input())
xy = [list(map(int, input().split())) for i in range(N)]

tilt_map = {}

for i in range(N):
    for j in range(i+1, N):
        a = xy[i]
        b = xy[j]
        tilt_x = a[0] - b[0]
        tilt_y = a[1] - b[1]
        key = str(tilt_x) + ":" + str(tilt_y)
        if key in tilt_map:
            tilt_map[key] += 1
        else:
            tilt_map[key] = 1


most_key = sorted(tilt_map.items(), key=lambda x: x[1], reverse=True)[0][0]

idx = most_key.index(":")
m_dx = int(most_key[:idx])
m_dy = int(most_key[idx+1:])

if m_dx == 0:
    if m_dy < 0:
        m_dy *= -1
    xy.sort(key=lambda x: x[1])
else:
    if m_dx < 0:
        m_dx *= -1
        m_dy *= -1
    xy.sort(key=lambda x:x[0])

pos = xy.pop(0)
cost = 1

while len(xy) > 0:
    next_x = pos[0] + m_dx
    next_y = pos[1] + m_dy
    for _xy in xy[::]:
        if _xy[0] == next_x and _xy[1] == next_y:
            xy.remove([next_x, next_y])
            pos = [next_x, next_y]
            break
    else:
        pos = xy.pop(0)
        cost += 1
print(cost)


Fixed submission:

N = int(input())
xy = [list(map(int, input().split())) for i in range(N)]
xy.sort(key=lambda x: x[0])
tilt_map = {}

if N == 1:
    print(1)
else:
    for i in range(N):
        for j in range(i+1, N):
            a = xy[i]
            b = xy[j]
            tilt_x = a[0] - b[0]
            tilt_y = a[1] - b[1]
            if tilt_x == 0 and tilt_y < 0:
                tilt_y *= -1
            key = str(tilt_x) + ":" + str(tilt_y)
            if key in tilt_map:
                tilt_map[key] += 1
            else:
                tilt_map[key] = 1


    most_tilt = sorted(tilt_map.items(), key=lambda x: x[1], reverse=True)[0][1]
    print(N-most_tilt)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
a = [int(input()) for i in range(M)]
dp = [0 for i in range(N)]

mod = 10**9+7

for i in range(0, N)[::-1]:
    if i in a:
        dp[i] = 0
        continue
    if i == N-1:
        dp[N - 1] = 1
        continue
    if i == N-2:
        dp[N - 2] = 1 + dp[N - 1]
        continue
    dp[i] = (dp[i+1] + dp[i+2])%mod

print(dp[0])

Fixed submission:
N, M = map(int, input().split())
a = [int(input()) for i in range(M)]
dp = [0 for i in range(N)]

mod = 10**9+7
stair_set = set(range(0, N)[::-1])
stair_set = stair_set - set(a)
stair_list = list(stair_set)
stair_list.sort(reverse=True)

for i in stair_list:
    if i == N-1:
        dp[N - 1] = 1
        continue
    if i == N-2:
        dp[N - 2] = 1 + dp[N - 1]
        continue
    dp[i] = (dp[i+1] + dp[i+2])%mod

print(dp[0])
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
a = list(map(int, input().split()))
bc = [list(map(int, input().split())) for i in range(M)]

a.sort()

for i in range(M):
    b = bc[i][0]
    c = bc[i][1]
    a.extend([c for i in range(b)])

a.sort(reverse=True)
print(sum(a[:N]))

Fixed submission:
N, M = map(int, input().split())
a = list(map(int, input().split()))
bc = [list(map(int, input().split())) for i in range(M)]

a.sort()
bc.sort(key=lambda x:x[1],reverse=True)

cnt = 0
for i in range(M):
    b = bc[i][0]
    c = bc[i][1]
    a.extend([c for i in range(b)])
    cnt += b
    if cnt > N:
        break

a.sort(reverse=True)
print(sum(a[:N]))

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
a = list(map(int, input().split()))
bc = [list(map(int, input().split())) for i in range(M)]

def serarch(num, target, start):
    first = start
    last = len(target)
    while last - first > 1:
        if target[int((last + first)/2)] > num:
            last = (last + first)/2
        else:
            first = (last + first)/2
    return int(last)


a.sort()
bc.sort(key=lambda x: x[1])

idx = 0
for i in range(M):
    b = bc[i][0]
    c = bc[i][1]

    idx = serarch(c, a, idx)
    change_id = min(idx, b)
    a = a[change_id:idx] + [c for i in range(change_id)] + a[idx:]

print(sum(a))

Fixed submission:
N, M = map(int, input().split())
a = list(map(int, input().split()))
bc = [list(map(int, input().split())) for i in range(M)]

a.sort()
bc.sort(key=lambda x:x[1],reverse=True)

cnt = 0
for i in range(M):
    b = bc[i][0]
    c = bc[i][1]
    a.extend([c for i in range(b)])
    cnt += b
    if cnt > N:
        break

a.sort(reverse=True)
print(sum(a[:N]))

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
a = list(map(int, input().split()))
bc = [list(map(int, input().split())) for i in range(M)]

def serarch(num, target):
    first = 0
    last = len(target)
    while last - first > 1:
        if target[int((last + first)/2)] > num:
            last = (last + first)/2
        else:
            first = (last + first)/2
    return int(last)


a.sort()

for i in range(M):
    b = bc[i][0]
    c = bc[i][1]

    idx = serarch(c, a)
    change_id = min(idx, b)
    a = a[change_id:idx] + [c for i in range(change_id)] + a[idx:]

print(sum(a))

Fixed submission:
N, M = map(int, input().split())
a = list(map(int, input().split()))
bc = [list(map(int, input().split())) for i in range(M)]

a.sort()
bc.sort(key=lambda x:x[1],reverse=True)

cnt = 0
for i in range(M):
    b = bc[i][0]
    c = bc[i][1]
    a.extend([c for i in range(b)])
    cnt += b
    if cnt > N:
        break

a.sort(reverse=True)
print(sum(a[:N]))
Buggy python submission (verdict: Time Limit Exceeded):
from decimal import *
N, K = map(int, input().split())

ans = Decimal(0)
if K <= N:
    ans += Decimal(max(N-K+1, 0))/Decimal(N)
thres = N+1
if K <= N:
    thres = K

for i in range(1, thres):
    p = Decimal(1/N)
    score = Decimal(i)
    while score < K:
        score = score * Decimal(2)
        p = p / Decimal(2)
    ans = ans + p

print(ans)



Fixed submission:
from decimal import *
N, K = map(int, input().split())

ans = Decimal(0)
if K <= N:
    ans += Decimal(max(N-K+1, 0))/Decimal(N)
thres = N+1
if K <= N:
    thres = K

for i in range(1, thres):
    p = Decimal(1/N)
    score = Decimal(i)
    while score < K:
        score = score * Decimal(2)
        p = p / Decimal(2)
    ans = ans + p

print(ans)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input())

print(N + 1 - K)

Fixed submission:
N, K = map(int, input().split())

print(N + 1 - K)
Buggy python submission (verdict: Runtime Error):
a, b, c = [int(i) for i in input().split()]

if a <= c and c <= b:
    print("Yes")
elif: b <= c and c <= a:
    print("Yes")
else:
    print("No")

Fixed submission:
a, b, c = [int(i) for i in input().split()]

if a <= c and c <= b:
    print("Yes")
elif b <= c and c <= a:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
n = int(input())
c = [int(input()) for _ in range(n)]
v_c = []
for i,v in enumerate(c):
    if i > 0 and v == c[i-1]:
        continue
    v_c.append(v)

dp = [1]*(n+1)
color_cnt = [-1]*(2*10**5)
for i in range(len(v_c)-1, -1, -1):
    color = v_c[i]
    if color_cnt[color] > 0:
        # 増やす
        dp[i] = dp[i+1] + dp[color_cnt[color]]
    else:
        dp[i] = dp[i+1]
    color_cnt[color] = i
print(dp[0])


Fixed submission:
n = int(input())
c = [int(input()) for _ in range(n)]
v_c = []
MOD = 10**9+7

for i,v in enumerate(c):
    if i > 0 and v == c[i-1]:
        continue
    v_c.append(v)

dp = [1]*(n+1)
color_cnt = [-1]*(2*10**5+5)
for i in range(1, len(v_c)+1):
    color = v_c[i-1]
    if color_cnt[color] > 0:
        dp[i] = dp[i-1] + dp[color_cnt[color]]
    else:
        dp[i] = dp[i-1]
    dp[i] %= MOD
    color_cnt[color] = i
print(dp[len(v_c)])
Buggy python submission (verdict: Time Limit Exceeded):
a, b = [int(i) for i in input().split()]

map = [0 for i in range(40)]

for n in range(a, b+1):
    n_str = format(n, "040b")
    for i in range(len(n_str)):
        map[i] ^= int(n_str[i])
ans = 0
map.reverse()
for i in range(len(n_str)):
    ans += (2**i) * map[i]

print(ans)




Fixed submission:
a, b = map(int, input().split())

# n までに2**(i-1)が何個含まれるか

def solve(n, i):
    res = 0
    mod = 2**i
    c = n // mod
    res += c*mod//2
    if n % mod >= mod//2:
        res += (n%mod - mod//2 + 1)
    return res

b_list = [0]*40
a_list = [0]*40
ans = 0
for i in range(1, 41):
    num_l = solve(b, i)
    num_r = solve(a-1, i)
    num_one = num_l - num_r
    if num_one% 2 == 1:
        ans += 2**(i-1)
print(ans)
Buggy python submission (verdict: Runtime Error):
from functions import gcd
a, b, k = map(int, input().split())

_gcd = gcd(a, b)

count = 0
for i in range(1, _gcd+1)[::-1]:
    if a % i == 0 and b % i == 0:
        count += 1
    if count == k:
        print(i)
        break


Fixed submission:
from fractions import gcd
a, b, k = map(int, input().split())

_gcd = gcd(a, b)

count = 0
for i in range(1, _gcd+1)[::-1]:
    if a % i == 0 and b % i == 0:
        count += 1
    if count == k:
        print(i)
        break

Buggy python submission (verdict: Runtime Error):
from functools import gcd
a, b, k = map(int, input().split())

_gcd = gcd(a, b)

count = 0
for i in range(1, _gcd+1)[::-1]:
    if a % i == 0 and b % i == 0:
        count += 1
    if count == k:
        print(i)
        break


Fixed submission:
from fractions import gcd
a, b, k = map(int, input().split())

_gcd = gcd(a, b)

count = 0
for i in range(1, _gcd+1)[::-1]:
    if a % i == 0 and b % i == 0:
        count += 1
    if count == k:
        print(i)
        break
Buggy python submission (verdict: Time Limit Exceeded):
A, B, Q = map(int, input().split())
s = [int(input()) for i in range(A)]
t = [int(input()) for i in range(B)]
x = [int(input()) for i in range(Q)]


def binary_search(list, a):
    r = 0
    l = len(list)-1
    while l - r > 1:
        if list[(r+l)//2] > a:
            l = (r+l)//2
        else:
            r = (r+l)//2
    return r, l


def cost(start, s, t):
    if s == t:
        return abs(start - s)

    min_o = min(s, t)
    max_o = max(s, t)
    if start <= min_o:
        return max_o - start
    elif start <= max_o:
        return min(abs(start-min_o), abs(start-max_o)) + (max_o-min_o)
    else:
        return start - min_o


for start in x:
    s_r, s_l = binary_search(s, start)
    s_r_t_r, s_r_t_l = binary_search(t, s[s_r])
    s_l_t_r, s_l_t_l = binary_search(t, s[s_l])

    res0 = cost(start, s[s_r], t[s_r_t_r])
    res1 = cost(start, s[s_r], t[s_r_t_l])
    res2 = cost(start, s[s_l], t[s_l_t_r])
    res3 = cost(start, s[s_l], t[s_l_t_l])
    print(min(res0, res1, res2, res3))

Fixed submission:
import bisect
A, B, Q = map(int, input().split())
INF = 10**18
s = [-INF] + [int(input()) for i in range(A)] + [INF]
t = [-INF] + [int(input()) for i in range(B)] + [INF]
x = [int(input()) for i in range(Q)]



def cost(start, s, t):
    if s == t:
        return abs(start - s)

    min_o = min(s, t)
    max_o = max(s, t)
    if start <= min_o:
        return max_o - start
    elif start <= max_o:
        return min(abs(start-min_o), abs(start-max_o)) + (max_o-min_o)
    else:
        return start - min_o


for start in x:
    s_r = bisect.bisect_right(s, start)
    s_l = s_r - 1
    t_r = bisect.bisect_right(t, start)
    t_l = t_r - 1


    res0 = cost(start, s[s_r], t[t_r])
    res1 = cost(start, s[s_r], t[t_l])
    res2 = cost(start, s[s_l], t[t_r])
    res3 = cost(start, s[s_l], t[t_l])
    print(min(res0, res1, res2, res3))
Buggy python submission (verdict: Runtime Error):
from math import log2
N, K = map(int, input().split())
a = list(map(int, input().split()))
x = 0
if K == 0:
    x = 0
else:
    for i in range(int(log2(K))+1)[::-1]:
        cnt_1 = 0
        for _a in a:
            if _a & 2**i == 2**i:
                cnt_1 += 1
        if cnt_1 <= len(a)/2 and (x + 2**i) <= K:
            x += 2**i
            
ans = 0
for _a in a:
    ans += x ^ _a
print(ans)

Fixed submission:
import math
N, K = map(int, input().split())
a = list(map(int, input().split()))
x = 0
if K == 0:
    x = 0
else:
    for i in range(41)[::-1]:
        cnt_1 = 0
        for _a in a:
            if _a & 2**i == 2**i:
                cnt_1 += 1
        if cnt_1 <= len(a)/2 and (x + 2**i) <= K:
            x += 2**i

ans = 0
for _a in a:
    ans += x ^ _a
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from math import log2
N, K = map(int, input().split())
a = list(map(int, input().split()))
x = 0
if K == 0:
    x = 0
else:
    for i in range(int(log2(K))+1)[::-1]:
        cnt_1 = 0
        for _a in a:
            if _a & 2**i == 2**i:
                cnt_1 += 1
        if cnt_1 <= len(a)/2 and (x + 2**i) <= K:
            x += 2**i
            
ans = 0
for _a in a:
    ans += x ^ _a
print(ans)

Fixed submission:
import math
N, K = map(int, input().split())
a = list(map(int, input().split()))
x = 0
if K == 0:
    x = 0
else:
    for i in range(41)[::-1]:
        cnt_1 = 0
        for _a in a:
            if _a & 2**i == 2**i:
                cnt_1 += 1
        if cnt_1 <= len(a)/2 and (x + 2**i) <= K:
            x += 2**i

ans = 0
for _a in a:
    ans += x ^ _a
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import os
N, P = map(int, input().split())

if N == 1:
    print(P)
    os.sys.exit()
i = 2
ans = 1
while True:
    if i**N > P:
        break
    if P % i**N == 0:
        P /= i**N
        ans *= i
    else:
        i += 1

print(ans)

Fixed submission:
import os
N, P = map(int, input().split())

def trial_division(n):
    if n < 2:
        return []
    prime_factors = []
    for p in range(2, int( n**0.5)):
        if p*p > n: break
        cnt = 0
        while n % p == 0:
            cnt += 1
            n //= p
        prime_factors.append([p, cnt])
    if n > 1:
        prime_factors.append([n, 1])
    return prime_factors

prime_factors = trial_division(P)
ans = 1
for p in prime_factors:
    if p[1] >= N:
        ans *= p[0]**(p[1] // N)
print(ans)

Buggy python submission (verdict: Runtime Error):
N, P = map(int, input().split())

i = 2
ans = 1
while True:
    if i**N > P:
        break
    if P % i**N == 0:
        P /= i**N
        ans *= i
    else:
        i += 1

print(ans)

Fixed submission:
import os
N, P = map(int, input().split())

def trial_division(n):
    if n < 2:
        return []
    prime_factors = []
    for p in range(2, int( n**0.5)):
        if p*p > n: break
        cnt = 0
        while n % p == 0:
            cnt += 1
            n //= p
        prime_factors.append([p, cnt])
    if n > 1:
        prime_factors.append([n, 1])
    return prime_factors

prime_factors = trial_division(P)
ans = 1
for p in prime_factors:
    if p[1] >= N:
        ans *= p[0]**(p[1] // N)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, P = map(int, input().split())

i = 2
ans = 1
while True:
    if i**N > P:
        break
    if P % i**N == 0:
        P /= i**N
        ans *= i
    else:
        i += 1

print(ans)

Fixed submission:
import os
N, P = map(int, input().split())

def trial_division(n):
    if n < 2:
        return []
    prime_factors = []
    for p in range(2, int( n**0.5)):
        if p*p > n: break
        cnt = 0
        while n % p == 0:
            cnt += 1
            n //= p
        prime_factors.append([p, cnt])
    if n > 1:
        prime_factors.append([n, 1])
    return prime_factors

prime_factors = trial_division(P)
ans = 1
for p in prime_factors:
    if p[1] >= N:
        ans *= p[0]**(p[1] // N)
print(ans)
Buggy python submission (verdict: Runtime Error):
N, X = map(int, input().split())

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

ans = 0

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


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

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

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

ans = 0

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


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

Buggy python submission (verdict: Runtime Error):
N, X = map(int, input().split())

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

ans = 0

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


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

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

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

ans = 0

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


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