Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=998244353
def input(): return sys.stdin.readline().rstrip()

def main():
    N,S=map(int,input().split())
    A=list(map(int,input().split()))
    dp=[[[0]*3 for _ in range(S+1)] for _ in range(N+1)]
    dp[0][0][0]=1
    for i in range(N):
        for j in range(S+1):
            dp[i+1][j][0]+=dp[i][j][0]
            dp[i+1][j][0]%=MOD
            dp[i+1][j][1]+=dp[i][j][0]+dp[i][j][1]
            dp[i+1][j][1]%=MOD
            dp[i+1][j][2]+=dp[i][j][0]+dp[i][j][1]+dp[i][j][2]
            dp[i+1][j][2]%=MOD
            if j+A[i]<=S:
                dp[i+1][j+A[i]][1]+=dp[i][j][0]+dp[i][j][1]
                dp[i+1][j+A[i]][1]%=MOD
                dp[i+1][j+A[i]][2]+=dp[i][j][0]+dp[i][j][1]
                dp[i+1][j+A[i]][2]%=MOD
    print(dp[-1][-1][2])

if __name__ == '__main__':
    main()


Fixed submission:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=998244353
def input(): return sys.stdin.readline().rstrip()

def main():
    N,S=map(int,input().split())
    A=list(map(int,input().split()))
    dp0=[[0 if i!=0 else 1 for i in range(S+1)] for _ in range(N+1)]
    dp1=[[0]*(S+1) for _ in range(N+1)]
    dp2=[[0]*(S+1) for _ in range(N+1)]
    for i in range(N):
        for j in range(S+1):
            b=int(j==0)
            dp1[i+1][j]+=dp1[i][j]+b
            dp2[i+1][j]+=dp1[i][j]+dp2[i][j]+b
            dp1[i+1][j]%=MOD
            dp2[i+1][j]%=MOD
            if j+A[i]<=S:
                dp1[i+1][j+A[i]]+=dp1[i][j]+b
                dp2[i+1][j+A[i]]+=dp1[i][j]+b
                dp1[i+1][j+A[i]]%=MOD
                dp2[i+1][j+A[i]]%=MOD
    print(dp2[-1][-1])

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys
from math import sqrt,isclose

sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    a,b,c=map(int,input().split())
    if sqrt(a)+sqrt(b)<sqrt(c):
        if isclose(sqrt(a)+sqrt(b), sqrt(c), abs_tol=1e-06):
            print('No')
        else:
            print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()


Fixed submission:
# -*- coding: utf-8 -*-
import sys
import numpy as np

sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    a,b,c=map(np.float128,input().split())
    
    if a+b+2*np.sqrt(a*b)<c:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N,P=map(int,input().split())
    A=list(map(int,list(input())[::-1]))
    MOD=P
    S=[0]*(N+1)
    for i in range(N):
        S[i+1]=(S[i]+A[i]*pow(10,i,MOD))%MOD
    l=[0]*2019
    ans=0
    for i in range(N+1):
        ans+=l[S[i]]
        l[S[i]]+=1
    print(ans)


if __name__ == '__main__':
    main()



Fixed submission:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=2019
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N,P=map(int,input().split())
    A=list(map(int,list(input())[::-1]))
    ans=0
    if P==2 or P==5:
        if P==2:
            s=set([i*2 for i in range(5)])
        else:
            s=set([i*5 for i in range(2)])
        for i,x in enumerate(A[::-1],1):
            if x in s:
                ans+=i
    else:
        S=[0]*(N+1)
        for i in range(N):
            S[i+1]=(S[i]+A[i]*pow(10,i,P))%P
        l=[0]*P
        for i in range(N+1):
            ans+=l[S[i]]
            l[S[i]]+=1
    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
# coding: UTF-8
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    N,M=map(int,input().split())
    s,c=[0]*M,[0]*M
    d={}
    for i in range(M):
        s,c=map(int,input().split())
        if s in d:
            if c!=d[s]:
                print(-1)
                exit()
        else:
            d[s]=c
    if N!=1 and d[1]==0:
        print(-1)
        exit()
    ans=''
    for i in range(1,N+1):
        if i in d:
            ans+=str(d[i])
        else:
            if i==0:
                ans+='1'
            else:
                ans+='0'
    print(ans)

    

if __name__ == '__main__':
    main()


Fixed submission:
# coding: UTF-8
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    N,M=map(int,input().split())
    s,c=[0]*M,[0]*M
    d={}
    for i in range(M):
        s,c=map(int,input().split())
        if s in d:
            if c!=d[s]:
                print(-1)
                exit()
        else:
            d[s]=c
    if N!=1 and 1 in d and d[1]==0:
        print(-1)
        exit()
    ans=''
    if N==1 and M==0:
        print(0)
        exit()
    for i in range(1,N+1):
        if i in d:
            ans+=str(d[i])
        else:
            if i==1:
                ans+='1'
            else:
                ans+='0'
    print(ans)

    

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import sys
from fractions import gcd
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input():
    return sys.stdin.readline().rstrip()

def main():
    N,M=map(int,input().split())
    a=tuple(map(int,input().split()))
    for x in a:
        if x%2:
            raise Exception
    print(0)

        

if __name__ == '__main__':
    main()


Fixed submission:
import sys
from fractions import gcd
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input():
    return sys.stdin.readline().rstrip()

def main():
    N,M=map(int,input().split())
    a=tuple(map(lambda x:int(x)//2,input().split()))
    t=a[0]
    c=0
    while True:
        if t%2==0:
            c+=1
            t//=2
        else:
            break
    l=a[0]
    for x in a[1:]:
        if x%(2**c)!=0 or x%(2**(c+1))==0:
            print(0)
            exit()
        l=l*x//gcd(l,x)
    print((M+l)//(l*2))

        

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N=int(input())
    C=list(map(int,input().split()))
    
    def COMinit(n,MOD):
        fac,finv,inv=[0]*max(2,n+1),[0]*max(2,n+1),[0]*max(2,n+1)
        fac[0]=fac[1]=1
        finv[0]=finv[1]=1
        inv[1]=1
        for i in range(2,(n+1)):
            fac[i]=fac[i-1]*i%MOD
            inv[i]=MOD-inv[MOD%i]*(MOD//i)%MOD
            finv[i]=finv[i-1]*inv[i]%MOD
        return fac,finv,inv
    
    fac,finv,inv=COMinit(N,MOD)
    
    def COM(n, k, MOD):
        if n<k or n<0 or k<0:
            return 0
        return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD
    
    C.sort(reverse=1)
    ans=0
    for i in range(N):
        ans+=(pow(2,i,MOD)+i*pow(2,i-1,MOD))*2*pow(2,N-(i+1),MOD)*C[i]
        ans%=MOD
    ans*=pow(2,N-1,MOD)
    ans%=MOD
    print(ans)

if __name__ == '__main__':
    main()


Fixed submission:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N=int(input())
    C=list(map(int,input().split()))
    
    def COMinit(n,MOD):
        fac,finv,inv=[0]*max(2,n+1),[0]*max(2,n+1),[0]*max(2,n+1)
        fac[0]=fac[1]=1
        finv[0]=finv[1]=1
        inv[1]=1
        for i in range(2,(n+1)):
            fac[i]=fac[i-1]*i%MOD
            inv[i]=MOD-inv[MOD%i]*(MOD//i)%MOD
            finv[i]=finv[i-1]*inv[i]%MOD
        return fac,finv,inv
    
    fac,finv,inv=COMinit(N,MOD)
    
    def COM(n, k, MOD):
        if n<k or n<0 or k<0:
            return 0
        return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD
    
    def modinv(a, mod):
        b,u,v = mod,1,0
        while b:
            t=a//b
            a-=t*b
            a,b=b,a
            u-=t*v
            u,v=v,u
        u%=mod
        if u < 0:
            u+=mod
        return u

    def modpow(n,k,MOD):
        if k<0:
            return pow(modinv(n,MOD),-k,MOD)
        else:
            return pow(n,k,MOD)
    
    C.sort(reverse=1)
    ans=0
    for i in range(N):
        ans+=(modpow(2,i,MOD)+i*modpow(2,i-1,MOD))*2*modpow(2,N-(i+1),MOD)*C[i]
        ans%=MOD
    ans*=pow(2,N-1,MOD)
    ans%=MOD
    print(ans)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    S=list(map(int,list(input())))
    l={}
    for i in range(10):
        l[i]={}
        for j in range(10):
            l[i][j]=[]
    ans=0
    for i in range(N):
        for j in range(N-i-1):
            for k in range(N-i-j-2):
                if not S[i+j+k+2] in l[S[i]][S[i+j+1]]:
                    l[S[i]][S[i+j+1]].append(S[i+j+k+2])
                    ans+=1
    print(ans)
                

if __name__ == '__main__':
    main()


Fixed submission:
import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    S=list(map(int,list(input())))
    z=[None]*10
    for i in range(10):
        for j in range(N-2):
            if S[j]==i:
                 z[i]=j
                 break
    y=[[None]*10 for _ in range(10)]
    for x in range(10):
        if z[x] is not None:
            for i in range(10):
                for j in range(z[x]+1,N-1):
                    if S[j]==i:
                        y[x][i]=j
                        break
    ans=0
    for h in range(10):
        for x in range(10):
            if y[h][x] is not None:
                for i in range(10):
                    for j in range(y[h][x]+1,N):
                        if S[j]==i:
                            ans+=1
                            break
    print(ans)
                

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    N,K=map(int,input().split())
    A=list(map(int,input().split()))
    B=[0]*N
    ans=0
    for i in range(N):
        B[i]=A[i]%K
        z=B[i]
        for j in range(min(K-1,i+1)):
            if z==j+1:
                ans+=1
            z+=B[i-(1+j)]
            z%=K
    print(ans)
    

if __name__ == '__main__':
    main()


Fixed submission:
import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    N,K=map(int,input().split())
    A=list(map(int,input().split()))
    B=[0]*(N+1)
    for i in range(N):
        B[i+1]=(A[i]+B[i]-1)%K
    ans=0
    d={}
    for i in range(1,N+1):
        if i-K<0:
            if B[i-1] in d:
                d[B[i-1]]+=1
            else:
                d[B[i-1]]=1
        else:
            if B[i-1] in d:
                d[B[i-1]]+=1
            else:
                d[B[i-1]]=1
            d[B[i-K]]-=1
        if B[i] in d:
            ans+=d[B[i]]
    print(ans)
    

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import sys
from bisect import bisect_left,bisect_right
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

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

edge=[[] for _ in range(N)]
edges=[]
s=set([N-1])
for _ in range(M):
    l,r,c=map(int,input().split())
    l-=1
    edges.append((l,r,c))
    s.add(l)
V=list(s)
V.sort()
for l,r,c in edges:
    left=bisect_right(V,l)
    right=bisect_left(V,r)
    for i in V[left:right]:
        edge[l].append((c,i))
from heapq import heappop,heappush
# edges=[[(cost1,v1),(cost2,v2)],...]
def dijkstra(start,n,edges):
    d=[INF]*n
    used=[False]*n
    d[start]=0
    used[start]=True
    edgelist=[]
    for edge in edges[start]:
        heappush(edgelist,edge)
    while edgelist:
        minedge=heappop(edgelist)
        if used[minedge[1]]:
            continue
        v=minedge[1]
        d[v]=minedge[0]
        used[v]=True
        for edge in edges[v]:
            if not used[edge[1]]:
                heappush(edgelist,(edge[0]+d[v],edge[1]))
    return d

d=dijkstra(0,N,edge)
print(d[-1] if d[-1]!=INF else -1)

Fixed submission:
# -*- coding: utf-8 -*-
import sys
from bisect import bisect_left,bisect_right
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

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

edge=[[] for _ in range(N)]
for i in range(N-1):
    edge[i+1].append((0,i))
for _ in range(M):
    l,r,c=map(int,input().split())
    l-=1
    r-=1
    edge[l].append((c,r))

from heapq import heappop,heappush
# edges=[[(cost1,v1),(cost2,v2)],...]
def dijkstra(start,n,edges):
    d=[INF]*n
    used=[False]*n
    d[start]=0
    used[start]=True
    edgelist=[]
    for edge in edges[start]:
        heappush(edgelist,edge)
    while edgelist:
        minedge=heappop(edgelist)
        if used[minedge[1]]:
            continue
        v=minedge[1]
        d[v]=minedge[0]
        used[v]=True
        for edge in edges[v]:
            if not used[edge[1]]:
                heappush(edgelist,(edge[0]+d[v],edge[1]))
    return d

d=dijkstra(0,N,edge)
print(d[-1] if d[-1]!=INF else -1)
Buggy python submission (verdict: Runtime Error):
import numpy as np

N=int(input())
a=int(np.sqrt(N))
b=float('inf')
for i in range(1,a+1):
    if N%i==0:
        if i+N//i<b:
            ans=i

print(ans+N//ans-2)


Fixed submission:
import numpy as np

N=int(input())
a=int(np.sqrt(N))
b=float('inf')
for i in range(1,a+1):
    if N%i==0:
        if i+N//i<b:
            ans=i

print(ans+N//ans-2)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
L=list(map(int,input().split()))

s=0
for i in range(N):
    for j in range(N-1-i):
        for k in range(N-2-i-j):
            if ((L[i]<L[i+j+1]+L[i+j+k+2]) and (L[i+j+1]<L[i]+L[i+j+k+2])) and(L[i+j+k+2]<L[i]+L[i+j+1]):
                s+=1
print(s)


Fixed submission:
from heapq import *
from bisect import *

N=int(input())
L=list(map(int,input().split()))
h=[]
for i in range(N):
    heappush(h,L[i])
h2=[]
for i in range(N):
    heappush(h2,heappop(h))
s=0
for i in range(N):
    for j in range(N-1-i):
        bmc=h2[j+i+1]-h2[i]
        bpc=h2[j+i+1]+h2[i]
        a=-bisect_right(h2, bmc)+bisect_left(h2, bpc)-1
        if a>0:
            s+=a
            if bmc < h2[i]:
                s-=1
print(s//3)
Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())
h=list(map(int,input().split()))
s=0
for i in h:
  s+=1 if i => K else 0
print(s)

Fixed submission:
N,K=map(int,input().split())
h=list(map(int,input().split()))
s=0
for i in h:
  s+=1 if i >= K else 0
print(s)
Buggy python submission (verdict: Runtime Error):
import numpy
N=int(input())
A=list(map(int,input().split()))
s=numpy.argsort(A)
print(' '.join(s))


Fixed submission:
import numpy as np
N=int(input())
A=list(map(int,input().split()))
s=list(np.argsort(A))
print(' '.join(repr(e+1) for e in s))

Buggy python submission (verdict: Runtime Error):
inport numpy
N=int(input())
A=list(map(int,input().split()))
s=numpy.argsort(A)
print(' '.join(s))

Fixed submission:
import numpy as np
N=int(input())
A=list(map(int,input().split()))
s=list(np.argsort(A))
print(' '.join(repr(e+1) for e in s))
Buggy python submission (verdict: Runtime Error):
import Collections
A,B=map(int,input().split())
def gcd(a,b):
  if b == 1:
    return a
  return furui(b,a%b)

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

print(len(collections.Counter(prime_factorize(gcd(A,B)).keys)+1)


Fixed submission:
import collections
A,B=map(int,input().split())
def gcd(a,b):
  if b == 0:
    return a
  return gcd(b,a%b)

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

print(len(list(collections.Counter(prime_factorize(gcd(A,B))).keys()))+1)

Buggy python submission (verdict: Runtime Error):
import Collections
A,B=map(int,input().split())
def gcd(a,b):
  if b == 1:
    return a
  return furui(b,a%b)

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

print(len(collections.Counter(prime_factorize(gcd(A,B)).keys)+1)

Fixed submission:
import collections
A,B=map(int,input().split())
def gcd(a,b):
  if b == 0:
    return a
  return gcd(b,a%b)

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

print(len(list(collections.Counter(prime_factorize(gcd(A,B))).keys()))+1)
Buggy python submission (verdict: Runtime Error):
H,W,A,B=map(int,input().split())
if A*H == B*W:
    str = '1'*A + '0'*(W-A)
    for i in range(H):
        print(str)
        str = str[W-A:]+str[:-A]
elif A == 0 and B == 0:
    for i in range(H)
        print('1'*W)
elif A == 0:
    for i in range(H):
        print('1'*W if i < B else '0'*W)
elif B == 0:
    for i in range(H):
        print('1'*A+'0'*(W-A))
else:
    print('No')

Fixed submission:
H,W,A,B=map(int,input().split())
for i in range(H):
    print('1'*A+'0'*(W-A) if i < B else '0'*A+'1'*(W-A))
Buggy python submission (verdict: Runtime Error):
if s == 'Sunny':
    print('Cloudy')
elif s == 'Cloudy':
    print('Rainy')
else:
    print('Sunny')

Fixed submission:
s=input()
if s == 'Sunny':
    print('Cloudy')
elif s == 'Cloudy':
    print('Rainy')
else:
    print('Sunny')

Buggy python submission (verdict: Runtime Error):
if s == 'Sunny':
    print('Cloudy')
elif s == 'Cloudy':
    print('Rainy')
else:
    primt('Sunny')

Fixed submission:
s=input()
if s == 'Sunny':
    print('Cloudy')
elif s == 'Cloudy':
    print('Rainy')
else:
    print('Sunny')
Buggy python submission (verdict: Runtime Error):
N,K,Q = map(int,input().split())
string_list=[int(input()) for i in range(Q)]
a = [K-Q]*N
for i in string_list:
    a[i] += 1
for i in a:
    print('Yes' if i > 0 else 'No')

Fixed submission:
N,K,Q = map(int,input().split())
string_list=[int(input()) for i in range(Q)]
a = [K-Q]*N
for i in string_list:
    a[i-1] += 1
for i in a:
    print('Yes' if i > 0 else 'No')
Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
h=[]
li = input().split()
for i in li:
    heapq.heappush(h, -int(i))

for i in range(M):
    z = heapq.heappop(h) / 2
    heapq.heappush(h, z)
c=0
for i in h:
    c += int(i)
print(-c)

Fixed submission:
import heapq
N,M = map(int,input().split())
h=[]
li = input().split()
for i in li:
    heapq.heappush(h, -int(i))

for i in range(M):
    z = heapq.heappop(h) / 2
    heapq.heappush(h, z)
c=0
for i in h:
    c += int(i)
print(-c)
Buggy python submission (verdict: Runtime Error):
 N = int(input())
 print(N**3)

Fixed submission:
N = int(input())
print(N**3)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    N,Q=map(int,input().split())
    a=[0]*(N-1)
    b=[0]*(N-1)
    cns=[[] for _ in range(N)]
    for i in range(N-1):
        a[i],b[i]=map(lambda x: int(x)-1,input().split())
        cns[a[i]].append(b[i])
        cns[b[i]].append(a[i])
    l_x=[0]*N
    for i in range(Q):
        p,x=map(int,input().split())
        l_x[p-1]+=x
    c=[0]*N
    c[0]+=l_x[0]
    def saiki(pn,ppn,x):
        for cn in cns[pn]:
            if cn != ppn:
                z=x+l_x[cn]
                c[cn]+=z
                saiki(cn,pn,z)
        return
    saiki(0,0,c[0])
    print(*c)
    

if __name__ == '__main__':
    main()


Fixed submission:
import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    N,Q=map(int,input().split())
    a=[0]*(N-1)
    b=[0]*(N-1)
    cns=[[] for _ in range(N)]
    for i in range(N-1):
        a[i],b[i]=map(lambda x: int(x)-1,input().split())
        cns[a[i]].append(b[i])
        cns[b[i]].append(a[i])
    l_x=[0]*N
    for i in range(Q):
        p,x=map(int,input().split())
        l_x[p-1]+=x
    c=[0]*N
    c[0]+=l_x[0]
    def saiki(pn,ppn,x):
        for cn in cns[pn]:
            if cn != ppn:
                z=x+l_x[cn]
                c[cn]+=z
                saiki(cn,pn,z)
        return
    saiki(0,0,c[0])
    print(*c)
    

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    N,Q=map(int,input().split())
    c=[0]*N
    d={}
    for i in range(N-1):
        a,b=map(int,input().split())
        d[b-1]=a-1
    d2={}
    for i in range(Q):
        p,x=map(int,input().split())
        if p-1 in d2:
            d2[p-1]+=x
        else:
            d2[p-1]=x
    if 0 in d2:
        c[0]+=d2[0]
    for i in range(1,N):
        if i in d2:
            c[i]+=d2[i]
        c[i]+=c[d[i]]
    print(*c)
    

if __name__ == '__main__':
    main()


Fixed submission:
import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    N,Q=map(int,input().split())
    a=[0]*(N-1)
    b=[0]*(N-1)
    cns=[[] for _ in range(N)]
    for i in range(N-1):
        a[i],b[i]=map(lambda x: int(x)-1,input().split())
        cns[a[i]].append(b[i])
        cns[b[i]].append(a[i])
    l_x=[0]*N
    for i in range(Q):
        p,x=map(int,input().split())
        l_x[p-1]+=x
    c=[0]*N
    c[0]+=l_x[0]
    def saiki(pn,ppn,x):
        for cn in cns[pn]:
            if cn != ppn:
                z=x+l_x[cn]
                c[cn]+=z
                saiki(cn,pn,z)
        return
    saiki(0,0,c[0])
    print(*c)
    

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
a = list(map(int,input().split()))
ans = ""
kaisu = a[0] * 2 +1
for i in kaisu:
    b = a[1] - a[0] + 1 + i
    ans = ans + str(b) + " "
print(ans[:-1])

Fixed submission:
a = list(map(int,input().split()))
ans = ""
kaisu = a[0] * 2 - 1
for i in range(kaisu):
    b = a[1] - a[0] + 1 + i
    ans = ans + str(b) + " "
print(ans[:-1])