Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python
# coding: utf-8

# In[29]:


def func():
    N,Q = map(int, input().split())
    ab = []
    nodes = {}
    for _ in range(N-1):
        ab.append(list(map(int, input().split())))
    ab = sorted(ab,key=lambda x:x[0])
    graph = {}
    for a,b in ab:
        if a not in graph:
            graph[a] = [b]
        else:
            graph[a].append(b)
    cnt = [0]*N
    for j in range(Q):
        p,x = map(int, input().split())
        calc(graph,p,cnt,x)
    print(*cnt)


# In[30]:


def calc(graph,node,cnt,x):
    cnt[node-1] += x
    if node in graph:
        for n in graph[node]:
            calc(graph,n,cnt,x)
    return cnt


# In[31]:


if __name__ == "__main__":
    func()


# In[ ]:






Fixed submission:
#!/usr/bin/env python
# coding: utf-8

# In[32]:


from collections import deque


# In[37]:


def func():
    N,Q = map(int, input().split())
    graph = [[] for _ in range(N)]
    for _ in range(N-1):
        a,b = map(int, input().split())
        a,b = a-1,b-1
        graph[a].append(b)
        graph[b].append(a)
    cnt = [0]*N
    for j in range(Q):
        p,x = map(int, input().split())
        cnt[p-1] += x
    q = deque([[0,-1,cnt[0]]])
    d = [-1]*N
    while q:
        cur,fr,p = q.popleft()
        d[cur] = p
        for nex in graph[cur]:
            if nex == fr:
                continue
            q.append([nex,cur,p+cnt[nex]])
    ans = []
    for i in range(N):
        ans.append(d[i])
    print(*ans)


# In[38]:


if __name__ == "__main__":
    func()


# In[ ]:

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python
# coding: utf-8

# In[23]:


def func():
    N,Q = map(int, input().split())
    ab = []
    nodes = {}
    for _ in range(N-1):
        ab.append(list(map(int, input().split())))
    ab = sorted(ab,key=lambda x:x[0])
    graph = {}
    for a,b in ab:
        if a not in graph:
            graph[a] = [b]
        else:
            graph[a].append(b)
    cnt = [0]*N
    for j in range(Q):
        p,x = map(int, input().split())
        calc(graph,p,cnt,x)
    print(cnt)


# In[26]:


def calc(graph,node,cnt,x):
    cnt[node-1] += x
    if node in graph:
        for n in graph[node]:
            calc(graph,n,cnt,x)
    return cnt


# In[28]:


if __name__ == "__main__":
    func()


# In[ ]:






Fixed submission:
#!/usr/bin/env python
# coding: utf-8

# In[32]:


from collections import deque


# In[37]:


def func():
    N,Q = map(int, input().split())
    graph = [[] for _ in range(N)]
    for _ in range(N-1):
        a,b = map(int, input().split())
        a,b = a-1,b-1
        graph[a].append(b)
        graph[b].append(a)
    cnt = [0]*N
    for j in range(Q):
        p,x = map(int, input().split())
        cnt[p-1] += x
    q = deque([[0,-1,cnt[0]]])
    d = [-1]*N
    while q:
        cur,fr,p = q.popleft()
        d[cur] = p
        for nex in graph[cur]:
            if nex == fr:
                continue
            q.append([nex,cur,p+cnt[nex]])
    ans = []
    for i in range(N):
        ans.append(d[i])
    print(*ans)


# In[38]:


if __name__ == "__main__":
    func()


# In[ ]:
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python
# coding: utf-8

# In[12]:


import collections


# In[10]:


N = int(input())
s = []
for _ in range(N):
    s.append(input())


# In[18]:


ans = 0
for i in range(N-1):
    for j in range(i+1,N):
        if collections.Counter(s[i]) == collections.Counter(s[j]):
            ans += 1
print(ans)



Fixed submission:
#!/usr/bin/env python
# coding: utf-8

# In[12]:


import collections


# In[10]:


N = int(input())
s = []
for _ in range(N):
    s.append(input())


# In[30]:


ans = 0
mydict = {}
for i in range(N):
    tmp = "".join(sorted(s[i]))
    if tmp not in mydict:
        mydict[tmp] = 1
    else:
        ans += mydict[tmp]
        mydict[tmp] += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python
# coding: utf-8

# In[10]:


N = int(input())
s = []
for _ in range(N):
    s.append(input())


# In[11]:


ans = 0
for i in range(N-1):
    myset = set(s[i])
    for j in range(i+1,N):
        for x in myset:
            if s[i].count(x) != s[j].count(x):
                break
        else:
            ans += 1
print(ans)


# In[ ]:






Fixed submission:
#!/usr/bin/env python
# coding: utf-8

# In[12]:


import collections


# In[10]:


N = int(input())
s = []
for _ in range(N):
    s.append(input())


# In[30]:


ans = 0
mydict = {}
for i in range(N):
    tmp = "".join(sorted(s[i]))
    if tmp not in mydict:
        mydict[tmp] = 1
    else:
        ans += mydict[tmp]
        mydict[tmp] += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python
# coding: utf-8

# In[26]:


N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))


# In[27]:


ans = 0
for i in range(N):
    ans += min(A[i], B[i])
    B[i] = max(B[i]-A[i])


# In[ ]:






Fixed submission:
#!/usr/bin/env python
# coding: utf-8

# In[26]:


N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))


# In[28]:


ans = 0
for i in range(N):
    ans += min(A[i], B[i])
    B[i] = max(B[i]-A[i], 0)
    ans += min(A[i+1], B[i])
    A[i+1] = max(A[i+1]-B[i], 0)
print(ans)


# In[ ]:
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python
# coding: utf-8

# In[10]:


N = int(input())
A = []
for _ in range(N):
    A.append(int(input()))

for i in range(N):
    tmp = [x for x in A]
    del tmp[i]
    print(max(tmp))


# In[ ]:






Fixed submission:
#!/usr/bin/env python
# coding: utf-8

# In[1]:


N = int(input())
A = []
for _ in range(N):
    A.append(int(input()))


# In[6]:


idx_max = A.index(max(A))
tmp = [x for x in A]
del tmp[idx_max]
most_max = max(A)
second_max = max(tmp)
for i in range(N):
    if i == idx_max:
        print(second_max)
    else:
        print(most_max)


# In[ ]:
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python
# coding: utf-8

# In[1]:


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


# In[40]:


taste = list(range(L, N+L))


# In[41]:


choice = min(list(map(abs, taste)))
taste.remove(choice)
print(sum(taste))



Fixed submission:
#!/usr/bin/env python
# coding: utf-8

# In[67]:


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


# In[68]:


taste = list(range(L, N+L))


# In[69]:


choice_index = list(map(abs, taste)).index(min(list(map(abs, taste))))
del taste[choice_index]
print(sum(taste))


# In[ ]:
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python
# coding: utf-8

# In[129]:


import math


# In[124]:


A, B, C, D = map(int, input().split())


# In[130]:


lcm = int(C*D / math.gcd(C, D))


# In[131]:


c_part_a = int((A - 1) / C)
d_part_a = int((A - 1) / D)
cd_part_a = int((A - 1) / lcm)

c_part_b = int(B / C)
d_part_b = int(B / D)
cd_part_b = int(B / lcm)


# In[132]:


ans1 = (A-1) - (c_part_a + d_part_a - cd_part_a)
ans2 = B - (c_part_b + d_part_b - cd_part_b)


# In[133]:


print(ans2 - ans1)


# In[ ]:






Fixed submission:
#!/usr/bin/env python
# coding: utf-8

# In[8]:


import math


# In[5]:


A,B,C,D = map(int, input().split())


# In[14]:


ac = (A-1)//C
bc = B//C
ad = (A-1)//D
bd = B//D
a_both = (A-1)//(C*D//math.gcd(C,D))
b_both = B//(C*D//math.gcd(C,D))
print((B-A+1) - (bc-ac) - (bd-ad) + (b_both-a_both))


# In[ ]:

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python
# coding: utf-8

# In[90]:


import math


# In[102]:


A, B, C, D = map(int, input().split())


# In[103]:


lcm = int(C*D / math.gcd(C, D))


# In[104]:


c_part_a = int((A - 1) / C)
d_part_a = int((A - 1) / D)
cd_part_a = int((A - 1) / lcm)

c_part_b = int(B / C)
d_part_b = int(B / D)
cd_part_b = int(B / lcm)


# In[105]:


ans1 = (A-1) - (c_part_a + d_part_a - cd_part_a)
ans2 = B - (c_part_b + d_part_b - cd_part_b)


# In[106]:


print(ans2 - ans1)


# In[ ]:






Fixed submission:
#!/usr/bin/env python
# coding: utf-8

# In[8]:


import math


# In[5]:


A,B,C,D = map(int, input().split())


# In[14]:


ac = (A-1)//C
bc = B//C
ad = (A-1)//D
bd = B//D
a_both = (A-1)//(C*D//math.gcd(C,D))
b_both = B//(C*D//math.gcd(C,D))
print((B-A+1) - (bc-ac) - (bd-ad) + (b_both-a_both))


# In[ ]:

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python
# coding: utf-8

# In[90]:


import math


# In[102]:


A, B, C, D = map(int, input().split())


# In[103]:


lcm = int(C*D / math.gcd(C, D))


# In[104]:


c_part_a = int((A - 1) / C)
d_part_a = int((A - 1) / D)
cd_part_a = int((A - 1) / lcm)

c_part_b = int(B / C)
d_part_b = int(B / D)
cd_part_b = int(B / lcm)


# In[105]:


ans1 = (A-1) - (c_part_a + d_part_a - cd_part_a)
ans2 = B - (c_part_b + d_part_b - cd_part_b)


# In[106]:


print(ans2 - ans1)


# In[ ]:






Fixed submission:
#!/usr/bin/env python
# coding: utf-8

# In[8]:


import math


# In[5]:


A,B,C,D = map(int, input().split())


# In[14]:


ac = (A-1)//C
bc = B//C
ad = (A-1)//D
bd = B//D
a_both = (A-1)//(C*D//math.gcd(C,D))
b_both = B//(C*D//math.gcd(C,D))
print((B-A+1) - (bc-ac) - (bd-ad) + (b_both-a_both))


# In[ ]:
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python
# coding: utf-8

# In[3]:


import numpy as np


# In[25]:


N = int(input())
data = []
for i in range(N):
    data.append((list(map(int, input().split()))))


# In[26]:


data = np.array(data)


# In[27]:


sorted_data = data[np.argsort(data[:, 1])]


# In[28]:


flag = 0
for i in range(N):
    if sum(sorted_data[:i+1, 0]) > sorted_data[i, 1]:
        flag = 1
        break

if flag == 0:
    print("Yes")
else:
    print("No")


# In[ ]:






Fixed submission:
#!/usr/bin/env python
# coding: utf-8

# In[3]:


import numpy as np


# In[42]:


N = int(input())
data = []
for i in range(N):
    data.append((list(map(int, input().split()))))


# In[43]:


data = np.array(data)


# In[44]:


sorted_data = data[np.argsort(data[:, 1])]
cumsum_data = np.cumsum(sorted_data[:,0])


# In[45]:


flag = 0
for i in range(N):
    if cumsum_data[i] > sorted_data[i, 1]:
        flag = 1
        break

if flag == 0:
    print("Yes")
else:
    print("No")


# In[ ]:
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python
# coding: utf-8

# In[8]:


import math


# In[68]:


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


# In[71]:


ans = 0
for i in range(1,N+1):
    ans += (1/2)**(max(math.floor(math.log((K-1)/i, 2)) + 1, 0))/N


# In[72]:


print(ans)


# In[ ]:






Fixed submission:
#!/usr/bin/env python
# coding: utf-8

# In[8]:


import math


# In[68]:


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


# In[73]:


ans = 0
if K > 1:
    for i in range(1,N+1):
        ans += (1/2)**(max(math.floor(math.log((K-1)/i, 2)) + 1, 0))/N
else:
    ans = 1


# In[74]:


print(ans)


# In[ ]:
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python
# coding: utf-8

# In[6]:


N = int(input())
S = input()


# In[8]:


ans = N
for i in range(N+1):
    left = S[:i].count("#")
    right = S[i:].count(".")
    ans = min(ans, left+right)
print(ans)


# In[ ]:






Fixed submission:
#!/usr/bin/env python
# coding: utf-8

# In[6]:


N = int(input())
S = input()


# In[9]:


w = S.count(".")
b = 0
ans = min(w,N-w)
for i in range(N):
    if S[i] == ".":
        w -= 1
    else:
        b += 1
    ans = min(ans, w+b)
print(ans)


# In[ ]:
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python
# coding: utf-8

# In[13]:


abcde = []
for _ in range(5):
    abcde.append(int(input()))
print(sum(-(-x//10)*10 for x in abcde) + min(x%10 for x in abcde if x%10 != 0) - 10)


# In[ ]:






Fixed submission:
#!/usr/bin/env python
# coding: utf-8

# In[17]:


abcde = []
for _ in range(5):
    abcde.append(int(input()))
print(sum(-(-x//10)*10 for x in abcde) + min(x%10 if x%10 != 0 else 10 for x in abcde ) - 10)


# In[ ]:
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python
# coding: utf-8

# In[1]:


import numpy as np


# In[71]:


N,M = map(int, input().split())
data = []
for i in range(N):
    data.append(list(map(int, input().split())))


# In[72]:


data = np.array(data)


# In[84]:


sorted_data = data[np.argsort(data[:, 0])]


# In[87]:


ans = 0
for i in range(N):
    if sum(sorted_data[:, 1][:i + 1]) <= M:
        ans += sorted_data[i, 0] * sorted_data[i, 1]
        #print(i, sorted_data[i, 0], sum(sorted_data[:, 1][:i + 1]), ans)
    else:
        ans += sorted_data[i, 0] * (M - sum(sorted_data[:, 1][:i]))
        #print(i, sorted_data[i, 0], (M - sum(sorted_data[:, 1][:i])), ans)
        break

print(ans)


# In[ ]:






Fixed submission:
#!/usr/bin/env python
# coding: utf-8

# In[14]:


N,M = map(int, input().split())
AB = []
for _ in range(N):
    AB.append(list(map(int, input().split())))


# In[15]:


AB_s = sorted(AB, key=lambda x: x[0])

cnt = 0
ans = 0
for idx,lst in enumerate(AB_s):
#     print(lst)
    c = lst[0]
    n = lst[1]
    if n <= M-cnt:
        ans += c*n
        cnt += n
#         print(cnt)
    else:
        ans += c*(M-cnt)
        cnt += (M-cnt)
#         print(cnt)
        break
print(ans)


# In[ ]:

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python
# coding: utf-8

# In[1]:


import numpy as np


# In[71]:


N,M = map(int, input().split())
data = []
for i in range(N):
    data.append(list(map(int, input().split())))


# In[72]:


data = np.array(data)


# In[84]:


sorted_data = data[np.argsort(data[:, 0])]


# In[86]:


ans = 0
for i in range(N):
    if sum(sorted_data[:, 1][:i + 1]) < M:
        ans += sorted_data[i, 0] * sorted_data[i, 1]
        #print(i, sorted_data[i, 0], sum(sorted_data[:, 1][:i + 1]), ans)
    else:
        ans += sorted_data[i, 0] * (M - sum(sorted_data[:, 1][:i]))
        #print(i, sorted_data[i, 0], (M - sum(sorted_data[:, 1][:i])), ans)
        break

print(ans)


# In[ ]:






Fixed submission:
#!/usr/bin/env python
# coding: utf-8

# In[14]:


N,M = map(int, input().split())
AB = []
for _ in range(N):
    AB.append(list(map(int, input().split())))


# In[15]:


AB_s = sorted(AB, key=lambda x: x[0])

cnt = 0
ans = 0
for idx,lst in enumerate(AB_s):
#     print(lst)
    c = lst[0]
    n = lst[1]
    if n <= M-cnt:
        ans += c*n
        cnt += n
#         print(cnt)
    else:
        ans += c*(M-cnt)
        cnt += (M-cnt)
#         print(cnt)
        break
print(ans)


# In[ ]:
Buggy python submission (verdict: Runtime Error):

# coding: utf-8

# In[2]:


import sys


# In[18]:


A,B,K = map(int, input().split())


# In[19]:


def yakusuu(x):
    yakusuu_array = []

    for i in range(1, x):
        if num % i == 0:
            yakusuu_array.append(i)
    
    return yakusuu_array


# In[21]:


if K > 1:
    print(list(set(yakusuu(A)) & set(yakusuu(B)))[K-1])
else:
    print(1)



Fixed submission:

# coding: utf-8

# In[26]:


import sys


# In[106]:


A,B,K = map(int, input().split())


# In[107]:


def yakusuu(x):
    yakusuu_array = []

    for i in range(1, x+1):
        if x % i == 0:
            yakusuu_array.append(i)
    
    return yakusuu_array


# In[108]:


y_list = sorted(list(set(yakusuu(A)) & set(yakusuu(B))), reverse=True)


# In[109]:


print(y_list[K-1])

Buggy python submission (verdict: Runtime Error):

# coding: utf-8

# In[2]:


import sys


# In[18]:


A,B,K = map(int, input().split())


# In[19]:


def yakusuu(x):
    yakusuu_array = []

    for i in range(1, x):
        if num % i == 0:
            yakusuu_array.append(i)
    
    return yakusuu_array


# In[21]:


if K > 1:
    print(list(set(yakusuu(A)) & set(yakusuu(B)))[K-1])
else:
    print(1)



Fixed submission:

# coding: utf-8

# In[26]:


import sys


# In[106]:


A,B,K = map(int, input().split())


# In[107]:


def yakusuu(x):
    yakusuu_array = []

    for i in range(1, x+1):
        if x % i == 0:
            yakusuu_array.append(i)
    
    return yakusuu_array


# In[108]:


y_list = sorted(list(set(yakusuu(A)) & set(yakusuu(B))), reverse=True)


# In[109]:


print(y_list[K-1])
Buggy python submission (verdict: Runtime Error):

# coding: utf-8

# In[46]:


def main():
    N,M = map(int, input().split())
    A = list(map(int, input().split()))
    
    match = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
    
    result = [-1 for _ in range(N+1)]
    result[0] = 0
    
    print(result)
    
    for i in range(1, N+1):
        for a in A:
            if i < match[a]:
                print(i,a,result)
                continue
            result[i] = max(result[i], result[i-match[a]]*10+a)
            print(i,a,result)
    
    print(result[N])


# In[47]:


main()



Fixed submission:

# coding: utf-8

# In[1]:


def main():
    N,M = map(int, input().split())
    A = list(map(int, input().split()))
    
    match = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
    
    result = [-1 for _ in range(N+1)]
    result[0] = 0
    
    #print(result)
    
    for i in range(1, N+1):
        for a in A:
            if i < match[a]:
                #print(i,a,result)
                continue
            result[i] = max(result[i], result[i-match[a]]*10+a)
            #print(i,a,result)
    
    print(result[N])


# In[2]:


main()
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python
# coding: utf-8

# In[43]:


N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))


# In[44]:


if sum(A) < sum(B):
    ans = -1
else:
    diff_plus = sorted([B[i]-A[i] for i in range(N) if B[i]-A[i]>0])
    diff_minus = sorted([A[i]-B[i] for i in range(N) if A[i]-B[i]>0],reverse=True)
    if len(diff_plus) > 0:
        j = 0
        cnt = len(diff_plus)
        for i,x in enumerate(diff_plus):
            while sum(diff_minus[:j+1]) < x:
                j += 1
            diff_minus[j] = sum(diff_minus[:j+1])-x
            for k in range(j):
                diff_minus[k] = 0
        ans = j+1+cnt
    else:
        ans = 0
print(ans)


# In[ ]:






Fixed submission:
#!/usr/bin/env python
# coding: utf-8

# In[43]:


N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))


# In[45]:


# if sum(A) < sum(B):
#     ans = -1
# else:
#     diff_plus = sorted([B[i]-A[i] for i in range(N) if B[i]-A[i]>0])
#     diff_minus = sorted([A[i]-B[i] for i in range(N) if A[i]-B[i]>0],reverse=True)
#     if len(diff_plus) > 0:
#         j = 0
#         cnt = len(diff_plus)
#         for i,x in enumerate(diff_plus):
#             while sum(diff_minus[:j+1]) < x:
#                 j += 1
#             diff_minus[j] = sum(diff_minus[:j+1])-x
#             for k in range(j):
#                 diff_minus[k] = 0
#         ans = j+1+cnt
#     else:
#         ans = 0
# print(ans)


# In[47]:


husoku = [a-b for a, b in zip(A, B) if a-b < 0]
amari = [a-b for a, b in zip(A, B) if a-b > 0]
amari.sort(reverse=True)
 
H = abs(sum(husoku))
if len(husoku) == 0:
    ans = 0
elif H > sum(amari):
    ans = -1
else:
    for i, a in enumerate(amari, start=1):
        H -= a
        if H <= 0:
            ans = len(husoku) + i
            break
print(ans)


# In[ ]:
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python
# coding: utf-8

# In[13]:


S = list(input())


# In[14]:


ans = 0
for i in range(S.count("W")):
    ans += S.index("W")-i
    S[S.index("W")] = "B"
print(ans)


# In[ ]:






Fixed submission:
#!/usr/bin/env python
# coding: utf-8

# In[30]:


S = list(input())


# In[31]:


w_count = S.count("W")
print(sum([idx for idx,x in enumerate(S) if x == "W"]) - (w_count-1)*w_count//2)


# In[ ]:
Buggy python submission (verdict: Runtime Error):

# coding: utf-8

# In[3]:


import numpy as np


# In[19]:


n,k = map(int, input().split())
h = []
for _ in range(n):
    h.append(int(input()))


# In[20]:


h = np.array(h)


# In[21]:


sorted_h = np.sort(h)


# In[22]:


print(min(sorted_h[k-1:] - sorted_h[:k]))



Fixed submission:

# coding: utf-8

# In[3]:


import numpy as np


# In[38]:


n,k = map(int, input().split())
h = []
for _ in range(n):
    h.append(int(input()))


# In[43]:


h = np.array(h)
sorted_h = np.sort(h)
print(min(sorted_h[k-1:] - sorted_h[:-k+1]))
Buggy python submission (verdict: Runtime Error):

# coding: utf-8

# In[54]:


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


# In[42]:


def p(n):
    return 2 ** (n+1) - 1
def b(n):
    return 2 ** (n+1) - 2
def l(n):
    return 2 ** (n+2) - 3


# In[56]:


def func(i,x):
    if x <= l(i):
        if i == 0:
            if x == 1:
                return 1
            else:
                return 0
        else:
            if x <= 2**(i+1) - 2:
                return func(i-1, x-1)
            else:
                return p(i-1) + 1 + func(i-1, x-(2**(i+1)-2)-1,)


# In[57]:


print(func(n,x))



Fixed submission:

# coding: utf-8

# In[103]:


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


# In[104]:


def p(n):
    return 2 ** (n+1) - 1
def b(n):
    return 2 ** (n+1) - 2
def l(n):
    return 2 ** (n+2) - 3


# In[109]:


def func(i, x):
    if x == 0:
        return 0
    elif x <= l(i-1) + 1:
        return func(i-1, x-1)
    elif x == l(i-1) + 2:
        return p(i-1) + 1
    elif x <= 2 * l(i-1) + 2:
        return p(i-1) + 1 + func(i-1, x - l(i-1) - 2)
    else:
        return 2 * p(i-1) + 1


# In[110]:


print(func(n,x))

Buggy python submission (verdict: Runtime Error):

# coding: utf-8

# In[1]:


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


# In[5]:


def p(n):
    return 2 ** (n+1) - 1
def b(n):
    return 2 ** (n+1) - 2
def l(n):
    return 2 ** (n+2) - 3


# In[30]:


def func(i,x):
    if x > l(i):
        print("error")
    else:
        if i == 0:
            if x == 1:
                return 1
            else:
                return 0
        else:
            if x <= 2**(i+1) - 2:
                return func(i-1, x-1)
            else:
                return p(i-1) + 1 + func(i-1, x-(2**(i+1)-2)-1,)


# In[34]:


print(func(n,x))



Fixed submission:

# coding: utf-8

# In[103]:


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


# In[104]:


def p(n):
    return 2 ** (n+1) - 1
def b(n):
    return 2 ** (n+1) - 2
def l(n):
    return 2 ** (n+2) - 3


# In[109]:


def func(i, x):
    if x == 0:
        return 0
    elif x <= l(i-1) + 1:
        return func(i-1, x-1)
    elif x == l(i-1) + 2:
        return p(i-1) + 1
    elif x <= 2 * l(i-1) + 2:
        return p(i-1) + 1 + func(i-1, x - l(i-1) - 2)
    else:
        return 2 * p(i-1) + 1


# In[110]:


print(func(n,x))
Buggy python submission (verdict: Runtime Error):

# coding: utf-8

# In[12]:


import numpy as np


# In[65]:


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


# In[66]:


def usage(n):
    print('# 素因数')
    fct = factorize(n)
    print(fct, num(fct))
    
    print('# 約数')
    for div in divisorize(fct):
        print(div, num(div))


def factorize(n):
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct


def divisorize(fct):
    b, e = fct.pop()  # base, exponent
    pre_div = divisorize(fct) if fct else [[]]
    suf_div = [[(b, k)] for k in range(e + 1)]
    return [pre + suf for pre in pre_div for suf in suf_div]


def num(fct):
    a = 1
    for base, exponent in fct:
        a = a * base**exponent
    return a


# In[67]:


def func(n):
    fct = factorize(n)
    ret = []
    for div in divisorize(fct):
        ret.append(num(div))
    
    return ret


# In[68]:


div = np.array(func(M))


# In[69]:


print(div[div < M/N].max())



Fixed submission:
#!/usr/bin/env python
# coding: utf-8

# In[11]:


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


# In[12]:


def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


# In[14]:


for x in make_divisors(M)[::-1]:
    if M//x >= N:
        ans = x
        break
print(ans)


# In[ ]: