Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
def f(x):
  if x==1:
    return dict()
  y=x
  r=dict()
  for i in range(2,int(x**0.5)+1):
    if y%i==0:
      r[i]=0
      while y%i==0:
        r[i]+=1
        y=y//i
    if y==1:
      break
  if y!=1:
    r[y]=1
  return r

B=[f(A[i]) for i in range(N)]
G=dict()
def g(x,y):
  z=list(set(x.keys())|set(y.keys()))
  r=dict()
  for i in range(len(z)):
    r[z[i]]=max(x.get(z[i],0),y.get(z[i],0))
  return r

for i in range(N):
  G=g(G,B[i])
X=1
mod=10**9+7
P=0
Y=list(G.keys())
for i in range(len(Y)):
  X=X*pow(Y[i],G[Y[i]],mod)%mod
for i in range(N):
  P=(P+X*pow(A[i],mod-2,mod))%mod
print(P)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
def f(x):
  if x==1:
    return dict()
  y=x
  r=dict()
  for i in range(2,int(x**0.5)+1):
    if y%i==0:
      r[i]=0
      while y%i==0:
        r[i]+=1
        y=y//i
    if y==1:
      break
  if y!=1:
    r[y]=1
  return r

B=[f(A[i]) for i in range(N)]
def g(X):
  if len(X)==1:
    return X[0]
  a,b=g(X[:len(X)//2]),g(X[len(X)//2:])
  c=list(set(a.keys())|set(b.keys()))
  for i in range(len(c)):
    a[c[i]]=max(a.get(c[i],0),b.get(c[i],0))
  return a

G=g(B)
X=1
mod=10**9+7
P=0
Y=list(G.keys())
for i in range(len(Y)):
  X=X*pow(Y[i],G[Y[i]],mod)%mod
for i in range(N):
  P=(P+X*pow(A[i],mod-2,mod))%mod
print(P)
Buggy python submission (verdict: Runtime Error):
from heapq import *
import sys
I=sys.stdin.readlines()
N,K=map(int,I[0].split())
t,d=0,0
X=[]
for i in range(N):
  t,d=map(int,I[i+1].split())
  X.append((d,t))
X.sort()
Q=[]
heapify(Q)
C=[0]*N
V=0
S=0
for i in range(K):
  heappush(Q,X[-1])
  if C[X[-1][1]-1]==0:
    V+=1
  S+=X[-1][0]
  C[X[-1][1]-1]+=1
  del X[-1]
def f(q,c,s,x,v):
  y=0
  r=s+v*v
  for i in range(len(q)):
    y=heappop(q)
    if c[y[1]-1]>=2:
      s-=y[0]
      c[y[1]-1]-=1
      break
    if len(q)==0:
      return r
  for i in range(len(x)):
    if c[x[-1][1]-1]==0:
      heappush(q,x[-1])
      s+=x[-1][0]
      c[x[-1][1]-1]=1
      v+=1
      del x[-1]
      return max(r,f(q,c,s,x,v))
    del x[-1]
  return r
print(f(Q,C,S,X,V))

Fixed submission:
from heapq import *
import sys
sys.setrecursionlimit(10**6)
I=sys.stdin.readlines()
N,K=map(int,I[0].split())
t,d=0,0
X=[]
for i in range(N):
  t,d=map(int,I[i+1].split())
  X.append((d,t))
X.sort()
Q=[]
heapify(Q)
C=[0]*N
V=0
S=0
for i in range(K):
  heappush(Q,X[-1])
  if C[X[-1][1]-1]==0:
    V+=1
  S+=X[-1][0]
  C[X[-1][1]-1]+=1
  del X[-1]
def f(q,c,s,x,v):
  y=0
  r=s+v*v
  for i in range(len(q)):
    y=heappop(q)
    if c[y[1]-1]>=2:
      s-=y[0]
      c[y[1]-1]-=1
      break
    if len(q)==0:
      return r
  for i in range(len(x)):
    if c[x[-1][1]-1]==0:
      heappush(q,x[-1])
      s+=x[-1][0]
      c[x[-1][1]-1]=1
      v+=1
      del x[-1]
      return max(r,f(q,c,s,x,v))
    del x[-1]
  return r
print(f(Q,C,S,X,V))
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
G=[[] for i in range(N)]
a,b=0,0
for i in range(M):
  a,b=map(int,input().split())
  G[b-1].append(a-1)
DP=[-1]*N
def f(x):
  if DP[x]!=-1:
    return DP[x]
  DP[x]=0
  for i in range(len(G[x])):
    DP[x]=max(DP[x],f(G[x][i])+1)
  return DP[x]

for i in range(N):
  f(i)
print(max(DP))

Fixed submission:
import sys
sys.setrecursionlimit(10**9)
N,M=map(int,input().split())
G=[[] for i in range(N)]
a,b=0,0
for i in range(M):
  a,b=map(int,input().split())
  G[b-1].append(a-1)
DP=[-1]*N
def f(x):
  if DP[x]!=-1:
    return DP[x]
  DP[x]=0
  for i in range(len(G[x])):
    DP[x]=max(DP[x],f(G[x][i])+1)
  return DP[x]

for i in range(N):
  f(i)
print(max(DP))
Buggy python submission (verdict: Runtime Error):
N=int(input())
if N==1:
  print('''Yes
2
1
1'''
elif N==3:
  print('''Yes
3
2 1 2
2 3 1
2 2 3''')
else:
  print('No')

Fixed submission:
N=int(input())
X=0
for i in range(1,1000):
  X+=i
  if X==N:
    P=[[] for j in range(i+1)]
    X=0
    for j in range(i):
      for k in range(i-j):
        P[j].append(k+X+1)
      for k in range(i-j):
        P[k+j+1].append(k+X+1)
      X+=i-j
    print('Yes')
    print(i+1)
    for j in range(i+1):
      print(len(P[j]),end=' ')
      print(*P[j])
    exit()
print('No')
Buggy python submission (verdict: Runtime Error):
N,C=map(int,input().split())
D=[list(map(int,input().split())) for i in range(C)]
A=[list(map(int,input().split())) for i in range(N)]
X=[[0]*C for i in range(3)]
for c in range(C):
  for i in range(N):
    for j in range(N):
      X[(i+j)%3][c]+=D[A[i][j]][c]
P=10**20
for i in range(C):
  for j in range(C):
    for k in range(C):
      if len(set([i,j,k]))==3:
        P=min(P,X[0][i]+X[1][j]+X[2][k])
print(P)

Fixed submission:
N,C=map(int,input().split())
D=[list(map(int,input().split())) for i in range(C)]
A=[list(map(int,input().split())) for i in range(N)]
X=[[0]*C for i in range(3)]
for c in range(C):
  for i in range(N):
    for j in range(N):
      X[(i+j)%3][c]+=D[A[i][j]-1][c]
P=10**20
for i in range(C):
  for j in range(C):
    for k in range(C):
      if len(set([i,j,k]))==3:
        P=min(P,X[0][i]+X[1][j]+X[2][k])
print(P)
Buggy python submission (verdict: Runtime Error):
N,A,B=map(int,input().split())
if A+B-1>N or A*B<N:
  print(-1)
  exit()
Q=[[] for i in range(B)]
for i in range(N):
  Q[i//A].append(i+1)
Q=Q[::-1]
X=N-1
for i in range(B):
  if len(Q[i])==0:
    Q[i].append(Q[-(X//A+1+i)][-1])
    X+=1
    del Q[-((N-1)//A+1+i)][-1]
  else:
    break
P=[]
for i in range(B):
  for j in range(len(Q[i])):
    P.append(Q[i][j])
print(*P)

Fixed submission:
N,A,B=map(int,input().split())
if A+B-1>N or A*B<N:
  print(-1)
  exit()
Q=[[] for i in range(B)]
for i in range(N):
  Q[i//A].append(i+1)
Q=Q[::-1]
X=N-1
for i in range(B):
  if len(Q[i])==0:
    Q[i].append(Q[-(X//A+1)][-1])
    del Q[-(X//A+1)][-1]
    X-=1
  else:
    break
P=[]
for i in range(B):
  for j in range(len(Q[i])):
    P.append(Q[i][j])
print(*P)
Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())
A=sorted(filter(lambda x:x<K,list(map(int,input().split()))))
N=len(A)
def judge(x):
  DP=1
  Z=(1<<K)-1
  for i in range(N):
    if i!=x:
      DP=((DP|(DP<<A[i]))&Z)
  r=0
  for i in range(K-A[x],K):
    r|=(DP&(1<<i))
  return r

if judge(0):
  print(0)
  exit()
L,R,M=1,N,0
while L!=R:
  M=(L+R)//2
  if judge(M)==0:
    L=max(L+1,M)
  else:
    R=M
print(L)

Fixed submission:
N,K=map(int,input().split())
A=sorted(filter(lambda x:x<K,list(map(int,input().split()))))
N=len(A)
if N==0:
  print(0)
  exit()
def judge(x):
  DP=1
  Z=(1<<K)-1
  for i in range(N):
    if i!=x:
      DP=((DP|(DP<<A[i]))&Z)
  r=0
  for i in range(K-A[x],K):
    r|=(DP&(1<<i))
  return r

if judge(0):
  print(0)
  exit()
L,R,M=1,N,0
while L!=R:
  M=(L+R)//2
  if judge(M)==0:
    L=max(L+1,M)
  else:
    R=M
print(L)
Buggy python submission (verdict: Runtime Error):
D, T, S = map(int, input().split())

if not __debug__:
	print("Yes" if D < T * S else "No")
else:
    1/0

Fixed submission:
D, T, S = map(int, input().split())
print("Yes" if T * S >= D else "No")

Buggy python submission (verdict: Runtime Error):
import sys

assert sys.argv[1] == "ONLINE_JUDGE"


Fixed submission:
D, T, S = map(int, input().split())
print("Yes" if T * S >= D else "No")

Buggy python submission (verdict: Runtime Error):
import sys

print(sys.argv[2])

Fixed submission:
D, T, S = map(int, input().split())
print("Yes" if T * S >= D else "No")

Buggy python submission (verdict: Runtime Error):
import sys

print(sys.argv[3])

Fixed submission:
D, T, S = map(int, input().split())
print("Yes" if T * S >= D else "No")
Buggy python submission (verdict: Runtime Error):
N = int(input())
As = list(map(int, input().split()))

sA = sum(As) % (10 ** 9 + 7)
print((sA * sA - sum( (A * A % (10 ** 9 + 7) for A in As) ) ) * pow(2, -1, 10 ** 9 + 7) % (10 ** 9 + 7))

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

sA = sum(As) % (10 ** 9 + 7)
print((sA * sA - sum( (A * A % (10 ** 9 + 7) for A in As) ) ) * pow(2, -1, 10 ** 9 + 7) % (10 ** 9 + 7))
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict

root = 10000
MOD = 2 ** 61 - 1
def rolling_hash(s):
    hs = [0] * (len(s) + 1)
    for i in range(len(s)):
        hs[i + 1] = hs[i] * root + ord(s[i]) % MOD
    return hs

#"""
N = int(input())
S_list = [input() for _ in range(N)]
"""
def to_alpha(n):
    ret = ''
    while n > 0:
        n -= 1
        ret += chr(n % 26 + ord('a'))
        n //= 26
    return ret

N = 10 ** 5
S_list = [to_alpha(i) for i in range(2, 2 * N + 2, 2)]
#"""


S_list.sort(key=len)

ans = 0
wanted = {chr(i): set() for i in range(ord('a'), ord('z') + 1)}
for S in S_list:
    alpha_set = set()
    hash_of_S = rolling_hash(S)
    for i in range(len(S)):
        alpha_set.add(S[i])
        suffix_hash = (hash_of_S[len(S)] - hash_of_S[i+1] * pow(root, (len(S) - i - 1), MOD)) % MOD
        for alpha in alpha_set:
            if suffix_hash in wanted[alpha]:
                ans += 1

    suffix_of_S = (hash_of_S[len(S)] - hash_of_S[1] * pow(root, (len(S) - 1), MOD)) % MOD
    wanted[S[0]].add(suffix_of_S)

print(ans)


Fixed submission:
N = int(input())

two_fives = []
mapping = [[0] * 19 for _ in range(19)]
ans = 0
for _ in range(N):
    s = input()
    if '.' in s:
        m, x = s.split('.')
        A = int(m) * 10 ** 9 + int(x.ljust(9, '0'))
    else:
        A = int(s) * 10 ** 9

    for two in range(19):
        if A % 2 == 0:
            A //= 2
        else:
            break
    for five in range(19):
        if A % 5 == 0:
            A //= 5
        else:
            break
        
    two_fives.append((two, five))
    mapping[18 - two][18 - five] += 1
    if two >= 9 and five >= 9:
        ans -= 1 # excluding ai * ai

for i in range(18):
    for j in range(19):
        mapping[i+1][j] += mapping[i][j]

for i in range(19):
    for j in range(18):
        mapping[i][j+1] += mapping[i][j]


for two, five in two_fives:
    ans += mapping[two][five]

#print(ans)
ans //= 2
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.buffer.readline
N, K = map(int, input().split())
As = list(map(int, input().split()))
for i in range(K, N):
    print("Yes" if As[i] > As[i-K] else "No")


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

money = 1000
stock = 0
for i in range(N):
    if i == 0:
        if As[0] < As[1]:
            stock = money // As[0]
            money %= As[0]
    elif i == N - 1:
        money += As[i] * stock
        stock = 0
    else:
        if As[i-1] >= As[i] and As[i+1] >= As[i]:
            stock += money // As[i]
            money %= As[i]
        elif  As[i-1] <= As[i] and As[i+1] <= As[i]:
            money += As[i] * stock
            stock = 0

print(money)
Buggy python submission (verdict: Runtime Error):
N = map(int, input().split())
As = list(map(int, input().split()))

added = As[0] + As[1]
xored = 0
for A in As[2:]:
    xored ^= A

anded = added - xored
if anded % 2 == 1:
    print(-1)
    exit()
else:
    anded >>= 1

left_stones_l_A0 = '' # <= A[0] for sure.
left_stones_e_A0 = '' #not sure if this is <= A[0].
for i, (a, x) in enumerate(zip(format(anded, '045b'), format(xored, '045b'))):
    if x == '0':
        if a == '0':
            left_stones_l_A0 += '0'
            left_stones_e_A0 += '0'
        else:
            left_stones_l_A0 += '1'
            left_stones_e_A0 += '1'
    else:
        if a == '0':
            if int(left_stones_l_A0 + '1' + '1' * (44 - i), base = 2) <= As[0]:
                left_stones_l_A0 += '1'
            else:
                left_stones_l_A0 += '0'
            if int(left_stones_e_A0 + '1' + '0' * (44 - i), base = 2) <= As[0]:
                left_stones_e_A0 += '1'
            elif int(left_stones_e_A0 + '0' + '0' * (44 - i), base = 2) <= As[0]:
                left_stones_e_A0 += '0'
            else:
                left_stones_e_A0 = left_stones_l_A0
                raise ValueError
        else:
            print(-1)
            exit()

if int(left_stones_e_A0, base = 2) <= As[0]:
    ans = As[0] - int(left_stones_e_A0, base = 2)
else:
    ans = As[0] - int(left_stones_l_A0, base = 2)

if 0 <= ans < As[0]:
    print(ans)
else:
    print(-1)


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

added = As[0] + As[1]
xored = 0
for A in As[2:]:
    xored ^= A

anded = added - xored
if anded % 2 == 1:
    print(-1)
    exit()
else:
    anded >>= 1

left_stones_l_A0 = '' # <= A[0] for sure.
left_stones_e_A0 = '' #not sure if this is <= A[0].
for i, (a, x) in enumerate(zip(format(anded, '045b'), format(xored, '045b'))):
    if x == '0':
        if a == '0':
            left_stones_l_A0 += '0'
            left_stones_e_A0 += '0'
        else:
            left_stones_l_A0 += '1'
            left_stones_e_A0 += '1'
    else:
        if a == '0':
            if int(left_stones_l_A0 + '1' + '1' * (44 - i), base = 2) <= As[0]:
                left_stones_l_A0 += '1'
            else:
                left_stones_l_A0 += '0'
            if int(left_stones_e_A0 + '1' + '1' * (44 - i), base = 2) <= As[0]:
                left_stones_e_A0 += '1'
                left_stones_l_A0 = left_stones_e_A0
            elif int(left_stones_e_A0 + '1' + '0' * (44 - i), base = 2) <= As[0]:
                left_stones_l_A0 = left_stones_e_A0 + '0'
                left_stones_e_A0 += '1'
            elif int(left_stones_e_A0 + '0' + '0' * (44 - i), base = 2) <= As[0]:
                left_stones_e_A0 += '0'
            else:
                left_stones_e_A0 = left_stones_l_A0
        else:
            print(-1)
            exit()

if int(left_stones_e_A0, base = 2) <= As[0]:
    ans = As[0] - int(left_stones_e_A0, base = 2)
else:
    ans = As[0] - int(left_stones_l_A0, base = 2)

if 0 <= ans < As[0]:
    print(ans)
else:
    print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

N = int(input())
As = list(map(int, input().split()))

d = Counter(As)

Q = int(input())
for _ in range(Q):
    B, C = map(int, input().split())
    if B in d:
        d[C] += d[B]
        d[B] = 0
    
    print(sum(k*v for k, v in d.items()))

Fixed submission:
from collections import Counter

N = int(input())
As = list(map(int, input().split()))

d = Counter(As)
S = sum(k*v for k, v in d.items())
Q = int(input())
for _ in range(Q):
    B, C = map(int, input().split())
    if B in d:
        S += d[B] * (C-B)
        d[C] += d[B]
        d[B] = 0
    print(S)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
As = sorted(map(int, input().split()))

flgs = [True] * N
for i in range(N):
    if flgs[i]:
        for j in range(i+1, N):
            if As[j] == As[i]:
                flgs[i] = False
                flgs[j] = False
            elif As[j] % As[i] == 0:
                flgs[j] = False

print(flgs.count(True))


Fixed submission:
import numpy as np

N = int(input())
As = sorted(map(int, input().split()))

flgs = np.full(10**6+1, False)
flgs[As] = True

for i, A in enumerate(As):
    if flgs[A] == True:
        flgs[::A] = False
        if i+1 == len(As) or As[i+1] != A:
            flgs[A] = True

print(np.count_nonzero(flgs))
Buggy python submission (verdict: Time Limit Exceeded):
import queue

INF = 10 ** 9

H, W, K = map(int, input().split())
sx, sy, gx, gy = map(int, input().split())

sentinels = [-1] * (W+2)
MAP = [sentinels]
for _ in range(H):
    MAP.append( [-1] + list(map(lambda c: INF if c == '.' else -1, input())) + [-1] )
MAP.append(sentinels)

q = queue.Queue()
q.put((sx, sy))
MAP[sx][sy] = 0
while not q.empty():
    x, y = q.get()
    for d in range(1, K+1):
        if MAP[x+d][y] > MAP[x][y] + 1:
            MAP[x+d][y] = MAP[x][y] + 1
            q.put((x+d, y))
        elif MAP[x+d][y] < MAP[x][y] + 1:
            break
    for d in range(1, K+1):
        if MAP[x-d][y] > MAP[x][y] + 1:
            MAP[x-d][y] = MAP[x][y] + 1
            q.put((x-d, y))
        elif MAP[x-d][y] < MAP[x][y] + 1:
            break
    for d in range(1, K+1):
        if MAP[x][y+d] > MAP[x][y] + 1:
            MAP[x][y+d] = MAP[x][y] + 1
            q.put((x, y+d))
        elif MAP[x][y+d] < MAP[x][y] + 1:
            break
    for d in range(1, K+1):
        if MAP[x][y-d] > MAP[x][y] + 1:
            MAP[x][y-d] = MAP[x][y] + 1
            q.put((x, y-d))
        elif MAP[x][y-d] < MAP[x][y] + 1:
            break

if MAP[gx][gy] == INF:
    print(-1)
else:
    print(MAP[gx][gy])

Fixed submission:
import queue

INF = 10 ** 9

H, W, K = map(int, input().split())
sx, sy, gx, gy = map(int, input().split())

sentinels = [-1] * (W+2)
MAP = [sentinels]
for _ in range(H):
    MAP.append( [-1] + list(map(lambda c: INF if c == '.' else -1, input())) + [-1] )
MAP.append(sentinels)

q = queue.Queue()
q.put((sx, sy))
MAP[sx][sy] = 0
while not q.empty():
    x, y = q.get()
    for d in range(1, K+1):
        if MAP[x+d][y] > MAP[x][y] + 1:
            MAP[x+d][y] = MAP[x][y] + 1
            q.put((x+d, y))
        elif MAP[x+d][y] < MAP[x][y] + 1:
            break
    for d in range(1, K+1):
        if MAP[x-d][y] > MAP[x][y] + 1:
            MAP[x-d][y] = MAP[x][y] + 1
            q.put((x-d, y))
        elif MAP[x-d][y] < MAP[x][y] + 1:
            break
    for d in range(1, K+1):
        if MAP[x][y+d] > MAP[x][y] + 1:
            MAP[x][y+d] = MAP[x][y] + 1
            q.put((x, y+d))
        elif MAP[x][y+d] < MAP[x][y] + 1:
            break
    for d in range(1, K+1):
        if MAP[x][y-d] > MAP[x][y] + 1:
            MAP[x][y-d] = MAP[x][y] + 1
            q.put((x, y-d))
        elif MAP[x][y-d] < MAP[x][y] + 1:
            break

if MAP[gx][gy] == INF:
    print(-1)
else:
    print(MAP[gx][gy])
Buggy python submission (verdict: Runtime Error):
import sys
import numpy as np
from numba import njit
input = sys.stdin.buffer.readline

N = int(input())
vws = np.array([tuple(map(int, input().split())) for _ in range(N)], np.int32)

n = min(2**11, N)

@njit("i4[:, :](i4[:, :], )", cache = True)
def precompute(vws):
    dp = np.zeros((n, 10**5+1), np.int32)
    dp[0, vws[0, 1]:] = vws[0, 0]
    for i in range(1, n):
        v, w = vws[i]
        dp[i] = dp[(i-1)//2]
        dp[i, w:] = np.maximum(dp[(i-1)//2, :-w]+v, dp[i, w:])
    return dp

@njit("i4(i4[:], i4[:], i4, i4[:])", cache = True)
def func(vs, ws, L, dp_):
    bits = np.arange(1 << len(vs))
    values = np.zeros_like(bits, np.int32)
    weights = np.zeros_like(bits, np.int32)
    for i in range(len(vs)):
        indices = np.nonzero(np.bitwise_and(bits, 1<<i))
        values[indices] += vs[i]
        weights[indices] += ws[i]

    mask = (weights <= L)     
    return np.amax(dp_[L - weights[mask]] + values[mask])

dp = precompute(vws)

Q = int(input())
for _ in range(Q):
    V, L = map(int, input().split())
    V -= 1
    if V < n:
        print(dp[V, L])
    else:
        Vs = []
        while V >= n:
            Vs.append(V)
            V = (V-1) // 2
        vs = vws[Vs, 0]
        ws = vws[Vs, 1]
        print(func(np.array(vs, np.int32), np.array(ws, np.int32), L, dp[V]))


Fixed submission:
print(input()[:3])

Buggy python submission (verdict: Runtime Error):
import sys
import numpy as np
from numba import njit
input = sys.stdin.buffer.readline

N = int(input())
vws = [tuple(map(int, input().split())) for _ in range(N)]

n = min(2**10, N)

dp = np.zeros((n, 10**5+1), np.int32)
dp[0, vws[0][1]:] = vws[0][0]
for i in range(1, n):
    v, w = vws[i]
    dp[i] = dp[(i-1)//2]
    dp[i, w:] = np.maximum(dp[(i-1)//2, :-w]+v, dp[i, w:])

@njit("(i4[::], i4[::], i4, i4)", cache = True)
def func(vs, ws, V, L):
    bits = np.arange(1 << len(vs))
    values = np.zeros_like(bits, np.int32)
    weights = np.zeros_like(bits, np.int32)
    for i in range(len(vs)):
        indices = np.nonzero(np.bitwise_and(bits, 1<<i))
        values[indices] += vs[i]
        weights[indices] += ws[i]

    mask = (weights <= L)     
    print(np.amax(dp[V][L - weights[mask]] + values[mask]))


Q = int(input())
for _ in range(Q):
    V, L = map(int, input().split())
    V -= 1
    if V < n:
        print(dp[V][L])
    else:
        vws_choose = []
        while V >= n:
            vws_choose.append(vws[V])
            V = (V-1) // 2
        vs, ws = zip(*vws_choose)
        func(np.array(vs, np.int32), np.array(ws, np.int32), V, L)


Fixed submission:
print(input()[:3])
Buggy python submission (verdict: Time Limit Exceeded):
import queue
import sys

input = sys.stdin.readline

N, M = map(int, input().split())
path = [[] for _ in range(N)]
for _ in range(M):
    A, B = map(int, input().split())
    path[A-1].append(B-1)
    path[B-1].append(A-1)

parent = [-1] * (N)
parent[0] = 0

found = [False] * N
found[0] = True

depth = [10 ** 9] * N
depth[0] = 0

q = queue.Queue()
q.put(0)
while not q.empty():
    pos = q.get()
    possible_parent = []
    for next_room in path[pos]:
        if parent[next_room] == -1:
            if not found[next_room]:
                q.put(next_room)
                found[next_room] = True
                depth[next_room] = min(depth[next_room], depth[pos] + 1)
        else:
            possible_parent.append(next_room)

    for p1 in possible_parent:
        for p2 in possible_parent:
            if depth[p1] > depth[p2]:
                break
        else:
            parent[pos] = p1
            break

if -1 in parent:
    print("No")
else:
    print("Yes")
    for elem in parent[1:]:
        print(elem + 1)

Fixed submission:
import queue
import sys

input = sys.stdin.readline

N, M = map(int, input().split())
path = [[] for _ in range(N)]
for _ in range(M):
    A, B = map(int, input().split())
    path[A-1].append(B-1)
    path[B-1].append(A-1)

parent = [-1] * (N)
parent[0] = 0

found = [False] * N
found[0] = True

depth = [10 ** 9] * N
depth[0] = 0

q = queue.Queue()
q.put(0)
while not q.empty():
    pos = q.get()
    possible_parent = []
    for next_room in path[pos]:
        if parent[next_room] == -1:
            if not found[next_room]:
                q.put(next_room)
                found[next_room] = True
                depth[next_room] = min(depth[next_room], depth[pos] + 1)
        else:
            possible_parent.append(next_room)

    for p1 in possible_parent:
        for p2 in possible_parent:
            if depth[p1] > depth[p2]:
                break
        else:
            parent[pos] = p1
            break

if -1 in parent:
    print("No")
else:
    print("Yes")
    for elem in parent[1:]:
        print(elem + 1)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
As = list(map(int, input().split()))

path = [1]
for _ in range(N+10):
    next_A = As[path[-1] - 1]
    if next_A in path:
        break
    else:
        path.append(next_A)

before_loop = path.index(next_A)
loop_len = len(path) - before_loop

if K <= before_loop:
    print(path[K])
else:
    print(path[(K - before_loop) % loop_len + before_loop])


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

appeared = [False] * N
appeared[0] = True
path = [1]
for _ in range(N+10):
    next_A = As[path[-1] - 1]
    if appeared[next_A-1]:
        break
    else:
        path.append(next_A)
        appeared[next_A-1] = True

before_loop = path.index(next_A)
loop_len = len(path) - before_loop

if K <= before_loop:
    print(path[K])
else:
    print(path[(K - before_loop) % loop_len + before_loop])

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

path = [1]
for _ in range(N+10):
    next_A = As[path[-1] - 1]
    if next_A in path:
        break
    else:
        path.append(next_A)

before_loop = path.index(next_A)
loop_len = len(path) - before_loop

if K <= before_loop:
    print(path[K])
else:
    print(path[(K - before_loop) % loop_len + before_loop])


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

appeared = [False] * N
appeared[0] = True
path = [1]
for _ in range(N+10):
    next_A = As[path[-1] - 1]
    if appeared[next_A-1]:
        break
    else:
        path.append(next_A)
        appeared[next_A-1] = True

before_loop = path.index(next_A)
loop_len = len(path) - before_loop

if K <= before_loop:
    print(path[K])
else:
    print(path[(K - before_loop) % loop_len + before_loop])