Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import math
n = int(input())
K = int(input())

def calk1(n):
    m = int(math.log10(n))
    num = m * 9
    num += n//(10**m)
    return num

def calk2(n):
    m = int(math.log10(n))
    num = m * (m - 1) // 2 * 9**2
    num += (n//(10**m)-1) * m * 9
    num += calk1(n - (n//(10**m)*10**m))
    return num

def calk3(n):
    m = int(math.log10(n))
    num = m * (m - 1) * (m - 2) // 6 * 9**3
    num += (n//(10**m)-1) * (m * (m - 1) // 2 * 9**2)
    num += calk2(n - (n//(10**m)*10**m))
    return num
if n < 10 ** (K - 1): print(0)
else:
    if K == 1: print(calk1(n))
    elif K == 2: print(calk2(n))
    else: print(calk3(n))


Fixed submission:
import math
n = int(input())
K = int(input())

def calk1(n):
    if n == 0: return 0
    m = int(math.log10(n))
    num = m * 9
    num += n//(10**m)
    return num

def calk2(n):
    m = int(math.log10(n))
    num = m * (m - 1) // 2 * 9**2
    num += (n//(10**m)-1) * m * 9
    num += calk1(n - (n//(10**m)*10**m))
    return num

def calk3(n):
    m = int(math.log10(n))
    num = m * (m - 1) * (m - 2) // 6 * 9**3
    num += (n//(10**m)-1) * (m * (m - 1) // 2 * 9**2)
    num += calk2(n - (n//(10**m)*10**m))
    return num
if n < 10 ** (K - 1): print(0)
else:
    if K == 1: print(calk1(n))
    elif K == 2: print(calk2(n))
    else: print(calk3(n))

Buggy python submission (verdict: Runtime Error):
import math
n = int(input())
K = int(input())

def calk1(n):
    m = int(math.log10(n))
    num = m * 9
    num += n//(10**m)
    return num

def calk2(n):
    m = int(math.log10(n))
    num = m * (m - 1) // 2 * 9**2
    num += (n//(10**m)-1) * m * 9
    num += calk1(n - (n//(10**m)*10**m))
    return num

def calk3(n):
    m = int(math.log10(n))
    num = m * (m - 1) * (m - 2) // 6 * 9**3
    num += (n//(10**m)-1) * (m * (m - 1) // 2 * 9**2)
    num += calk2(n - (n//(10**m)*10**m))
    return num
    
if K == 1: print(calk1(n))
elif K == 2: print(calk2(n))
else: print(calk3(n))

Fixed submission:
import math
n = int(input())
K = int(input())

def calk1(n):
    if n == 0: return 0
    m = int(math.log10(n))
    num = m * 9
    num += n//(10**m)
    return num

def calk2(n):
    m = int(math.log10(n))
    num = m * (m - 1) // 2 * 9**2
    num += (n//(10**m)-1) * m * 9
    num += calk1(n - (n//(10**m)*10**m))
    return num

def calk3(n):
    m = int(math.log10(n))
    num = m * (m - 1) * (m - 2) // 6 * 9**3
    num += (n//(10**m)-1) * (m * (m - 1) // 2 * 9**2)
    num += calk2(n - (n//(10**m)*10**m))
    return num
if n < 10 ** (K - 1): print(0)
else:
    if K == 1: print(calk1(n))
    elif K == 2: print(calk2(n))
    else: print(calk3(n))
Buggy python submission (verdict: Time Limit Exceeded):
H, N = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]

max_ab = max(AB)
dp = [-1]*(H+max_ab[0]+1)
dp[0] = 0

for i in range(1, H + max_ab[0]):
    lst = [dp[i-AB[j][0]] + AB[j][1] for j in range(N) if (i >= AB[j][0] and dp[i-AB[j][0]]!=-1)]
    if lst!=[]:dp[i] = min(lst)

print(min([i for i in dp[H:-1] if i!=-1]))
               

Fixed submission:
H, N = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]

max_ab = max(AB)
dp = [10**10]*(H+max_ab[0])
dp[0] = 0

for i in range(1, H + max_ab[0]):
    dp[i] = min(dp[i - a] + b for a, b in AB)

print(min(dp[H:]))
Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())

maze = [['#']*(W+2)]
for i in range(H):
    maze.append(list('#'+input()+'#'))
maze.append(['#']*(W+2))

ans = 0
for ii in range(1,H+1):
    for jj in range(1,W+1):
        if maze[ii][jj]=='#':continue
        temp = deque()
        temp.append([ii,jj])
        mazenum = [[0]*(W+2) for _ in range(H+2)]
        mazenum[ii][jj] = 0
        visited = [[False]*(W+2) for _ in range(H+2)]
        visited[ii][jj] = True

        while temp:
            p = temp.popleft()
            m = mazenum[p[0]][p[1]]
            for i, j in [[p[0]-1,p[1]], [p[0]+1, p[1]], [p[0],p[1]-1],[p[0],p[1]+1]]:
                if maze[i][j]=='.':
                    if not visited[i][j]:
                        temp.append([i, j])
                        mazenum[i][j] = m + 1
                        visited[i][j]=True        
        ans = max(ans, max(max(mazenum)))     

print(ans)


Fixed submission:
from collections import deque
H, W = map(int, input().split())

maze = [['#']*(W+2)]
for i in range(H):
    maze.append(list('#'+input()+'#'))
maze.append(['#']*(W+2))
ans = 0

for ii in range(1,H+1):
    for jj in range(1,W+1):
        if maze[ii][jj]=='#':continue
        temp = deque()
        temp.append([ii,jj])
        mazenum = [[0]*(W+2) for _ in range(H+2)]
        mazenum[ii][jj] = 0
        visited = [[False]*(W+2) for _ in range(H+2)]
        visited[ii][jj] = True


        while temp:
            p = temp.popleft()
            m = mazenum[p[0]][p[1]]
            for i, j in [[p[0]-1,p[1]], [p[0]+1, p[1]], [p[0],p[1]-1],[p[0],p[1]+1]]:
                if maze[i][j]=='.':
                    if not visited[i][j]:
                        temp.append([i, j])
                        mazenum[i][j] = m + 1
                        visited[i][j]= True        
        ans = max(ans, max(max(x) for x in mazenum))

print(ans)
Buggy python submission (verdict: Runtime Error):
import math
N = int(input())

ans = 101

if N%2==1:ans=0
else:
    for i in range(int(math.log(N,5))):
        ans += N//(5**(i+1)*2)
print(ans)

Fixed submission:
import math
N = int(input())

ans = 0

if N%2==1:ans=0
else:
    for i in range(int(math.log(N+1,5))):
        ans += N//(5**(i+1)*2)
print(ans)

Buggy python submission (verdict: Runtime Error):
import math
N = int(input())

ans = 0

for i in range(int(math.log(N,5))):
    ans += N//(5**(i+1)*2)
print(ans)

Fixed submission:
import math
N = int(input())

ans = 0

if N%2==1:ans=0
else:
    for i in range(int(math.log(N+1,5))):
        ans += N//(5**(i+1)*2)
print(ans)
Buggy python submission (verdict: Runtime Error):
import math

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

ans = 0
a_max = max(a)
alog = int(math.log2(a_max))+1

for i in range(alog):
    cnt0 = 0
    cnt1 = 0
    for j in a:
        p = pow(2, i)
        cnt1 += ((j & p) == p)
        cnt0 += ((j & p) == 0)
    ans += (cnt0 * cnt1)*(2**i)%(10**9+7)

print(ans%(10**9+7))

Fixed submission:
import math
import  numpy as np

N = int(input())
a = np.array(list(map(int, input().split())))

ans = 0
a_max = max(a)

if a_max==0:alog=1
else:alog = int(math.log2(a_max))+1

for i in range(alog):
    p = pow(2, i)
    cnt = np.count_nonzero((a >> i)& 1 == 1)
    
    ans += cnt * (N - cnt)*(2**i)
print(ans%(10**9+7))

Buggy python submission (verdict: Runtime Error):
import numpy as np

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

na = np.array(a)

mat = np.bitwise_xor(na.reshape(N,1),na)

print(sum(sum(mat))//2%(10**9+7))

Fixed submission:
import math
import  numpy as np

N = int(input())
a = np.array(list(map(int, input().split())))

ans = 0
a_max = max(a)

if a_max==0:alog=1
else:alog = int(math.log2(a_max))+1

for i in range(alog):
    p = pow(2, i)
    cnt = np.count_nonzero((a >> i)& 1 == 1)
    
    ans += cnt * (N - cnt)*(2**i)
print(ans%(10**9+7))

Buggy python submission (verdict: Runtime Error):
import numpy as np

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

na = np.matrix(a)

mat = np.bitwise_xor(na.T,na)

mat_lst = list(mat)

print(((mat.sum())//2)%(10**9+7))

Fixed submission:
import math
import  numpy as np

N = int(input())
a = np.array(list(map(int, input().split())))

ans = 0
a_max = max(a)

if a_max==0:alog=1
else:alog = int(math.log2(a_max))+1

for i in range(alog):
    p = pow(2, i)
    cnt = np.count_nonzero((a >> i)& 1 == 1)
    
    ans += cnt * (N - cnt)*(2**i)
print(ans%(10**9+7))

Buggy python submission (verdict: Runtime Error):
import numpy as np

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

na = np.matrix(a)

mat = np.bitwise_xor(na.T,na)

print(((mat.sum())//2)%(10**9+7))

Fixed submission:
import math
import  numpy as np

N = int(input())
a = np.array(list(map(int, input().split())))

ans = 0
a_max = max(a)

if a_max==0:alog=1
else:alog = int(math.log2(a_max))+1

for i in range(alog):
    p = pow(2, i)
    cnt = np.count_nonzero((a >> i)& 1 == 1)
    
    ans += cnt * (N - cnt)*(2**i)
print(ans%(10**9+7))

Buggy python submission (verdict: Runtime Error):
import numpy as np

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

na = np.matrix(a)

mat = np.bitwise_xor(na.T,na)

print((np.sum(mat)//2)%(10**9+7))

Fixed submission:
import math
import  numpy as np

N = int(input())
a = np.array(list(map(int, input().split())))

ans = 0
a_max = max(a)

if a_max==0:alog=1
else:alog = int(math.log2(a_max))+1

for i in range(alog):
    p = pow(2, i)
    cnt = np.count_nonzero((a >> i)& 1 == 1)
    
    ans += cnt * (N - cnt)*(2**i)
print(ans%(10**9+7))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = list(input())

ans = []
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            ans.append(S[i]+S[j]+S[k])
ans_set = set(ans)
print(len(ans_set))

Fixed submission:
N = int(input())
S = list(input())

ans = []
a1 = []
for i in range(N-2):
    if S[i] in a1:continue
    a1.append(S[i])
    a2 = []
    for j in range(i+1,N-1):
        if S[j] in a2:continue
        a2.append(S[j])
        a3 = []
        for k in range(j+1,N):
            if S[k] in a3:continue
            a3.append(S[k])
            ans.append(S[i]+S[j]+S[k])
ans_set = set(ans)
print(len(ans_set))
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = [int(x) for x in input().split()]
MOD = 10**9 + 7
ans = 1

lst = [0] * 3

for aa in a:
    cnt = 0
    for i, l in enumerate(lst):
        if l == aa:
            cnt += 1
            j = i
    ans *= cnt
    ans %= MOD
    lst[j] += 1
print(ans%MOD)

Fixed submission:
N = int(input())
a = [int(x) for x in input().split()]
MOD = 10**9 + 7
ans = 1

lst = [0] * 3

for aa in a:
    cnt = 0
    j = -1
    for i, l in enumerate(lst):
        if l == aa:
            cnt += 1
            j = i
    if j == -1:
        ans = 0
        break
    ans *= cnt
    ans %= MOD
    lst[j] += 1

print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
a = [int(x) for x in input().split()]
MOD = 10**9 + 7
ans = 1

lst = [0] * 3

for aa in a:
    cnt = 0
    for i, l in enumerate(lst):
        if l == aa:
            cnt += 1
            j = i
    ans *= cnt
    lst[j] += 1
print(ans%MOD)

Fixed submission:
N = int(input())
a = [int(x) for x in input().split()]
MOD = 10**9 + 7
ans = 1

lst = [0] * 3

for aa in a:
    cnt = 0
    j = -1
    for i, l in enumerate(lst):
        if l == aa:
            cnt += 1
            j = i
    if j == -1:
        ans = 0
        break
    ans *= cnt
    ans %= MOD
    lst[j] += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
def framod(n, mod, a=1):
    for i in range(1,n+1):
        a=a * i % mod
    return a

def power(n, r, mod):
    if r == 0: return 1
    if r%2 == 0:
        return power(n*n % mod, r//2, mod) % mod
    if r%2 == 1:
        return n * power(n, r-1, mod) % mod

def comb(n, k, mod):
    a=framod(n, mod)
    b=framod(k, mod)
    c=framod(n-k, mod)
    return (a * power(b, mod-2, mod) * power(c, mod-2, mod)) % mod
  
X, Y = map(int,input().split())

m = (2*Y - X) / 3
n = (2*X - Y) / 3

ans = 0

if m.is_integer() and n.is_integer():
    m = int(m)
    n = int(n)
    if m<n:m, n = n, m
        
print(comb(m+n, n, 10**9+7))


Fixed submission:
def framod(n, mod, a=1):
    for i in range(1,n+1):
        a=a * i % mod
    return a

def power(n, r, mod):
    if r == 0: return 1
    if r%2 == 0:
        return power(n*n % mod, r//2, mod) % mod
    if r%2 == 1:
        return n * power(n, r-1, mod) % mod

def comb(n, k, mod):
    a=framod(n, mod)
    b=framod(k, mod)
    c=framod(n-k, mod)
    return (a * power(b, mod-2, mod) * power(c, mod-2, mod)) % mod
  
X, Y = map(int,input().split())

mm = (2*Y - X) / 3
nn = (2*X - Y) / 3

ans = 0

if mm.is_integer() and nn.is_integer():
    mm = int(mm)
    nn = int(nn)
    if mm >=0 and nn>=0:
        ans =comb(mm+nn, nn, 10**9+7)
      
print(ans)
Buggy python submission (verdict: Runtime Error):
S = input()

s = S.replace('<>', '<,>').replace('><', '>,<').split(',')
lst1 = [ss.count('<') - ss.count('>') for ss in s]

ans = [0]

for i in lst:
    if i > 0:
        ans += list(range(1,i+1))
    else:
        ans[-1] = max(ans[-1], -i)
        ans += list(range(-i-1,-1, -1))

print(sum(ans))

Fixed submission:
S = input()

lst = [1 if S[0]=='<' else -1]
for i in range(1, len(S)):
    if S[i] == S[i - 1]:
        if S[i]=='<':lst[-1] += 1
        else: lst[-1] -= 1
    else:
        if S[i]=='>':lst.append(-1)
        else: lst.append(1)
ans = [0]

for i in range(len(lst)):
    if lst[i] > 0:
        for j in range(0, lst[i] + 1):
            ans.append(j)
    else:
        ans[-1] = max(ans[-1], -lst[i])
        for j in range(0, -lst[i]):
            ans.append(-lst[i]-j-1)

print(sum(ans))

Buggy python submission (verdict: Runtime Error):
S = input()

lst = [1]
for i in range(1, len(S)):
    if S[i] == S[i - 1]:
        if S[i]=='<':lst[-1] += 1
        else: lst[-1] -= 1
    else:
        if S[i]=='>':lst.append(-1)
        else: lst.append(1)

ans = []
con = 0

for i in range(len(lst)):
    if lst[i] > 0:
        for j in range(0, lst[i] + 1):
            ans.append(j)
        con = lst[i]
    else:
        ans[-1] = max(con, -lst[i])
        for j in range(0, -lst[i]):
            ans.append(-lst[i]-j-1)
        cont = 0
print(sum(ans))

Fixed submission:
S = input()

lst = [1 if S[0]=='<' else -1]
for i in range(1, len(S)):
    if S[i] == S[i - 1]:
        if S[i]=='<':lst[-1] += 1
        else: lst[-1] -= 1
    else:
        if S[i]=='>':lst.append(-1)
        else: lst.append(1)
ans = [0]

for i in range(len(lst)):
    if lst[i] > 0:
        for j in range(0, lst[i] + 1):
            ans.append(j)
    else:
        ans[-1] = max(ans[-1], -lst[i])
        for j in range(0, -lst[i]):
            ans.append(-lst[i]-j-1)

print(sum(ans))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from itertools import combinations 
input = sys.stdin.readline

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

l.sort()
cnt = 0

for n,i in enumerate(l[:]):
    for m,j in enumerate(l[n+1:],n+1):

        cnt +=len(list([c for c in set(l[m+1:]) if c<=i+j-1]))

        
print(cnt)


Fixed submission:
import sys
from bisect import bisect_left
from itertools import combinations 

input = sys.stdin.readline
 
N = int(input())
l= list(map(int, input().split()))
 
l.sort()
cnt = 0
 
for n,i in enumerate(l[:N-2]):
    for m,j in enumerate(l[n+1:N-1],n+1):
        cnt += max(0,bisect_left(l,i+j)-(m+1)) 
        
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from itertools import combinations 
input = sys.stdin.readline

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

l.sort()
cnt = 0
lst=[]

for n,i in enumerate(l):
    for m,j in enumerate(l[n+1:],n+1):

        lst = list([c for c in set(l[m+1:]) if c<=i+j-1])
        cnt += len(lst)
        
print(cnt)


Fixed submission:
import sys
from bisect import bisect_left
from itertools import combinations 

input = sys.stdin.readline
 
N = int(input())
l= list(map(int, input().split()))
 
l.sort()
cnt = 0
 
for n,i in enumerate(l[:N-2]):
    for m,j in enumerate(l[n+1:N-1],n+1):
        cnt += max(0,bisect_left(l,i+j)-(m+1)) 
        
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from itertools import combinations 
input = sys.stdin.readline

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

l.sort()
cnt = 0

for n,i in enumerate(l):
    for m,j in enumerate(l[n+1:],n+1):
        lst=[]
        lst = list([c for c in set(l[m+1:]) if c<=i+j-1])
        cnt += len(lst)
       
print(cnt)


Fixed submission:
import sys
from bisect import bisect_left
from itertools import combinations 

input = sys.stdin.readline
 
N = int(input())
l= list(map(int, input().split()))
 
l.sort()
cnt = 0
 
for n,i in enumerate(l[:N-2]):
    for m,j in enumerate(l[n+1:N-1],n+1):
        cnt += max(0,bisect_left(l,i+j)-(m+1)) 
        
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from itertools import combinations 
input = sys.stdin.readline

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

l.sort()
cnt = 0

for a,b,c in combinations(l, 3):
    if abs(b-a)+1 <= c <= a+b-1:
        cnt += 1
        
print(cnt)


Fixed submission:
import sys
from bisect import bisect_left
from itertools import combinations 

input = sys.stdin.readline
 
N = int(input())
l= list(map(int, input().split()))
 
l.sort()
cnt = 0
 
for n,i in enumerate(l[:N-2]):
    for m,j in enumerate(l[n+1:N-1],n+1):
        cnt += max(0,bisect_left(l,i+j)-(m+1)) 
        
print(cnt)
Buggy python submission (verdict: Runtime Error):
A, B = map(int,input().split())

def primes(n):
    if n==1:return [1]
    
    p_max = int(n**0.5)
    primes = list(range(3,n+1,2))
    n_primes = len(primes)
    
    for i, prime in enumerate([j for j in primes if j!=0]):
        for k in range(i+prime, n_primes, prime):
            primes[k] = 0
    prime_a = list([j for j in primes if j!=0])
    
    if n%2==0:prime_a.append(2)
      
    for i, prime_ai in enumerate(prime_a):
        if n%prime_ai!=0:prime_a[i]=0
    return list([j for j in prime_a if j!=0])

a = set(primes(A))
b = set(primes(B))

c = a & b
print(len(c)+1)

Fixed submission:
A, B = map(int,input().split())

def gcd(x, y):
    if y==0:return x
    else:
        return gcd(y, x%y)

def factorize(n):
    b = 2
    fct = []
    
    while b*b <=n:
        while n%b==0:
            n //=b
            fct.append(b)
        b+=1
    if n>1:fct.append(n)
    return fct
      
c = gcd(A, B)

print(len(set(factorize(c)))+1)
Buggy python submission (verdict: Runtime Error):
N = int(input())

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

sum_A = min(B[0], B[1])

for i in range(N-1):
    sum_A += min(B[i:N-1])
print(sum_A)

Fixed submission:
N = int(input())

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

A = []
A.append(B[0])

for i in range(1, N-1):
    if B[i-1]<B[i]:
        A.append(B[i-1])
    else:A.append(B[i])
A.append(B[N-2])

print(sum(A))
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
N, Q =map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N-1)]
 
g = [[] for _ in range(N+1)]
for a, b in ab:
    g[b].append(a)
    g[a].append(b)
cnt = [0]*(N+1)
 
for _ in range(Q):
    p, x = map(int, input().split())
    cnt[p] += x
 
temp = [1]
visited = [0]*(N+1)
visited[1] = 1
 
while temp:
    q = temp.pop()   
    for i in g[q]:
        if visited[i] == 0:
            temp.append(i)
            visited[i] = 1
            cnt[i] += cnt[q]
print(*cnt[1:])
N, Q =map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N-1)]

g = [[] for _ in range(N+1)]
for a, b in ab:
    g[b].append(a)
    g[a].append(b)
cnt = [0]*(N+1)

for _ in range(Q):
    p, x = map(int, input().split())
    cnt[p] += x

temp = [1]
visited = [0]*(N+1)
visited[1] = 1

while temp:
    q = temp.pop()   
    for i in g[q]:
        if visited[i] == 0:
            temp.append(i)
            visited[i] = 1
            cnt[i] += cnt[q]
print(*cnt[1:])
提出情報
提出日時

Fixed submission:
import sys
input = sys.stdin.readline

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

bond_lst = list([list(map(int,input().split())) for _ in range(N-1)])
      
point_lst = [0]*(N+1)

for _ in range(Q):
    a, b = map(int, input().split())
    point_lst[a] += b

graph = {}

for a, b in bond_lst:
    if a in graph:graph[a].append(b)
    else:graph[a] = [b]
    if b in graph:graph[b].append(a)
    else:graph[b] = [a]
      
passed = [0]*(N+1)
nxt_lst = [1]
while nxt_lst:
    nxt = nxt_lst.pop()
    for i in graph[nxt]:
        if passed[i] == 1:continue
        point_lst[i] += point_lst[nxt]
        nxt_lst.append(i)
    passed[nxt] = 1
print(*point_lst[1:])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q =map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N-1)]

g = {}
for a, b in ab:
    if a in g: g[a].append(b)
    else: g[a] = [b]
    if b in g: g[b].append(a)
    else: g[b] = [a]

cnt = [0]*(N+1)

for _ in range(Q):
    p, x = map(int, input().split())
    cnt[p] += x

temp = [1]
visited = [0]*(N+1)
visited[1] = 1

while temp:
    q = temp.pop()   
    for i in g[q]:
        if visited[i] == 0:
            temp.append(i)
            visited[i] = 1
            cnt[i] += cnt[q]
print(*cnt[1:])


Fixed submission:
import sys
input = sys.stdin.readline

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

bond_lst = list([list(map(int,input().split())) for _ in range(N-1)])
      
point_lst = [0]*(N+1)

for _ in range(Q):
    a, b = map(int, input().split())
    point_lst[a] += b

graph = {}

for a, b in bond_lst:
    if a in graph:graph[a].append(b)
    else:graph[a] = [b]
    if b in graph:graph[b].append(a)
    else:graph[b] = [a]
      
passed = [0]*(N+1)
nxt_lst = [1]
while nxt_lst:
    nxt = nxt_lst.pop()
    for i in graph[nxt]:
        if passed[i] == 1:continue
        point_lst[i] += point_lst[nxt]
        nxt_lst.append(i)
    passed[nxt] = 1
print(*point_lst[1:])
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
t = input()

n = len(s)

if set(list(t)) != (set(list(s)) & set(list(t))): ans = -1
else:
    dct = {}

    for i, ss in enumerate(s):
        if ss in dct:
            dct[ss].append(i)
        else: dct[ss] = [i]

    idx = -1
    ans = 0
    for i, tt in enumerate(t):
        jdg = True
        for j in dct[tt]:
            if idx < j:
                idx = j
                jdg = False
                break
        if jdg:
            idx = dct[tt][0]
            ans += n
    ans += idx + 1

print(ans)

Fixed submission:
from bisect import bisect_right
s = input()
t = input()

n = len(s)

if set(list(t)) != (set(list(s)) & set(list(t))): ans = -1
else:
    dct = {}

    for i, ss in enumerate(s):
        if ss in dct:
            dct[ss].append(i)
        else: dct[ss] = [i]
    idx = -1
    ans = 0
    for tt in t:
        m = bisect_right(dct[tt], idx)
        if m == len(dct[tt]):
            idx = dct[tt][0]
            ans += n
        else:
            idx = dct[tt][m]
    ans += idx + 1

print(ans)
Buggy python submission (verdict: Runtime Error):
import os

input = sys.stdin.readline

N = int(input())

a = list(map(int, input().split()))

ans = False
b = [0]*N

for i in range(N, 0 ,-1):
    b_sum = 0
    for j in range(i, N+1, i):
        b_sum += b[j-1]
    if b_sum % 2 != a[i-1]: b[i-1] = 1
if b==[0]*N:print(0)      
else:
    print(sum(b))
    print(*[k+1 for k, l in enumerate(b) if l==1])

Fixed submission:
N = int(input())

a = list(map(int, input().split()))

ans = False
b = [0]*N


for i in range(N, 0 ,-1):
    b_sum = 0
    for j in range(i, N+1, i):
        b_sum += b[j-1]
    if b_sum % 2 != a[i-1]: b[i-1] = 1
if b==[0]*N:print(0)      
else:
    print(sum(b))
    print(*[k+1 for k, l in enumerate(b) if l==1])
Buggy python submission (verdict: Time Limit Exceeded):
import math

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

ans = 2019

for i, j in zip(range(2019), range(L, R)):
    for k in range(j+1, R+1):
        lr_mod = (j * k) % 2019
        if lr_mod < ans:
            ans = lr_mod

print(ans)

Fixed submission:
import math

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

ans = 2019

for i, j in zip(range(2019), range(L, R)):
    for k in range(j+1, min(L + 2019*2, R + 1)):
        lr_mod = (j * k) % 2019
        if lr_mod < ans:
            ans = lr_mod
        if ans==0:break
    if ans==0:break

print(ans)