Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N,P=map(int,input().split(' '))
S =list(map(int,list(input()[::-1])))
ans = 0
cnt = [0]*P
cnt[0]=1
tmp = 0
for i in range(N):
    tmp += S[i]*10**i
    cnt[tmp%P] += 1
if P==2 or P==5:
    if P==2:
        check=[0,2,4,6,8]
    else:
        check=[0,5]
    for n,i in enumerate(S):
        if int(i) in check:
            ans += N-n
else:
    for i in cnt:
        ans += i*(i-1)//2
print(ans)

Fixed submission:
N,P=map(int,input().split(' '))
S =list(map(int,list(input()[::-1])))
ans = 0
cnt = [0]*P
cnt[0]=1
tmp = 0
for n,i in enumerate(S):
    d=i*pow(10,n,P)
    tmp =(tmp+d)%P
    cnt[tmp] += 1
if P in [2,5]:
    if P==2:
        check=[0,2,4,6,8]
    else:
        check=[0,5]
    for n,i in enumerate(S):
        if i in check:
            ans += N-n
else:
    for i in cnt:
        ans += i*(i-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,P=map(int,input().split(' '))
S =input()
ans = 0
cnt = [0]*P
cnt[0]=1
for i in range(N):
    cnt[int(S[i:])%P] += 1
if P==2 or P==5:
    if P==2:
        check=[0,2,4,6,8]
    else:
        check=[0,5]
    for n,i in enumerate(S[::-1]):
        if int(i) in check:
            ans += N-n
else:
    for i in cnt:
        ans += i*(i-1)//2
print(ans)

Fixed submission:
N,P=map(int,input().split(' '))
S =list(map(int,list(input()[::-1])))
ans = 0
cnt = [0]*P
cnt[0]=1
tmp = 0
for n,i in enumerate(S):
    d=i*pow(10,n,P)
    tmp =(tmp+d)%P
    cnt[tmp] += 1
if P in [2,5]:
    if P==2:
        check=[0,2,4,6,8]
    else:
        check=[0,5]
    for n,i in enumerate(S):
        if i in check:
            ans += N-n
else:
    for i in cnt:
        ans += i*(i-1)//2
print(ans)
Buggy python submission (verdict: Runtime Error):
class UnionFind:
    def __init__(self,N):
        self.par =[-1 for i in range(N)]
    def find(self,x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x==y:
            return
        if self.par[x] > self.par[y]:
            x,y = y,x
        self.par[x] +=self.par[y]
        self.par[y] = x

    def size(self,x):
        if self.par[x] < 0:
            return -self.par[x]
        else:
            self.par[x] = self.size(self.par[x])
            return self.par[x]
    def same(self,x,y):
        return self.find(x)==self.find(y)

N,M,K=map(int,input().split(' '))
Friend = UnionFind(N)
pull = [-1] * N
for i in range(M):
    a,b = map(int,input().split(' '))
    Friend.unite(a-1,b-1)
    pull[a-1] -= 1
    pull[b-1] -= 1
for i in range(K):
    c,d=map(int,input().split(' '))
    if Friend.same(c-1,d-1):
        pull[c-1] -=1
        pull[d-1] -=1
print(' '.join([str(Friend.size(i)+pull[i]) for i in range(N)]))

Fixed submission:
class UnionFind:
    def __init__(self,N):
        self.par =[-1 for i in range(N)]
    def find(self,x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x==y:
            return
        if self.par[x] > self.par[y]:
            x,y = y,x
        self.par[x] +=self.par[y]
        self.par[y] = x

    def size(self,x):
        return -self.par[self.find(x)]
    def same(self,x,y):
        return self.find(x)==self.find(y)

N,M,K=map(int,input().split(' '))
Friend = UnionFind(N)
pull = [-1] * N
for i in range(M):
    a,b = map(int,input().split(' '))
    Friend.unite(a-1,b-1)
    pull[a-1] -= 1
    pull[b-1] -= 1
for i in range(K):
    c,d=map(int,input().split(' '))
    if Friend.same(c-1,d-1):
        pull[c-1] -=1
        pull[d-1] -=1
print(' '.join([str(Friend.size(i)+pull[i]) for i in range(N)]))
Buggy python submission (verdict: Runtime Error):
import math
N=int(input())
X=sorted(list(map(int,input().split(' '))))
ans =math.inf
for i in range(X[0],X[-1]+1):
    tmp = 0
    for j in X:
        tmp += (j-i)**2
    ans = min(ans,tmp)
print(ans)

Fixed submission:
N=int(input())
X=sorted(list(map(int,input().split(' '))))
ans = 10**9
for i in range(X[0],X[-1]+1):
    tmp = 0
    for j in X:
        tmp += (j-i)**2
    ans = min(ans,tmp)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split(' '))
P=list(map(int,input().split(' ')))
max_list=[]
max_tmp = 0
ans = 0
for i in range(N-K+1):
    tmp = sum(P[i:i+K])
    if tmp > max_tmp:
        max_list=P[i:i+K]
        max_tmp = tmp
for i in max_list:
    ans += (i+1)/2
print(ans)

Fixed submission:
N,K=map(int,input().split(' '))
P=list(map(int,input().split(' ')))
tmp = sum([(i+1)/2 for i in P[:K]])
ans = tmp
for i,j in zip(P,P[K:]):
    tmp +=(j+1)/2-(i+1)/2
    ans = max(ans,tmp)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split(' '))
P=list(map(int,input().split(' ')))
max_list=[]
max_tmp = 0
ans = 0
for i in range(N-K+1):
    tmp = sum(P[i:i+K])
    if tmp > max_tmp:
        max_list=P[i:i+K]
        max_tmp = tmp
for i in max_list:
    ans += (i+1)/2
print(ans)

Fixed submission:
N,K=map(int,input().split(' '))
P=list(map(int,input().split(' ')))
tmp = sum([(i+1)/2 for i in P[:K]])
ans = tmp
for i,j in zip(P,P[K:]):
    tmp +=(j+1)/2-(i+1)/2
    ans = max(ans,tmp)
print(ans)
Buggy python submission (verdict: Runtime Error):
from scipy.misc import comb
import math
N=input()
K=int(input())
if K !=1:
    ans = 0
elif len(N)<2:
    print(int(N))
    exit()
else:
    ans = 9
for i in range(2,len(N)):
    ans += 9*comb(i-1,K-1)*(9**(K-1))
ans += max(0,int(N[0])-1)*comb(len(N)-1,K-1)*9**(K-1)
if K==1:
    ans += 1
elif K==2:
    ans += 9*max(0,len(N)-2)+int(N[1])
else:
    ans += int(N[2])+max(0,len(N)-3)*9+max(0,int(N[1])-1)*max(0,len(N)-2)*9+comb(len(N)-2,2)*81
print(math.ceil(ans))

Fixed submission:
N=input()
K=int(input())
dp_0 = [[0]*(len(N)) for i in range(K+1)]
dp_1 = [[0]*(len(N)) for i in range(K+1)]
dp_0[0][0]=1
dp_0[1][0]=int(N[0])-1
dp_1[1][0]=1
for i in range(len(N)-1):
    for j in range(K+1):
        if j==K:
            dp_0[j][i+1] += dp_0[j][i]
        elif j==0:
            dp_0[j][i+1] =dp_0[j][i]
            dp_0[j+1][i+1] += dp_0[j][i]*9
        else:
            dp_0[j][i+1] += dp_0[j][i]
            dp_0[j+1][i+1] += dp_0[j][i]*9
        if j != K and N[i+1] != '0':
            dp_0[j+1][i+1] += (int(N[i+1])-1)*dp_1[j][i]
            dp_0[j][i+1] += dp_1[j][i]
            dp_1[j+1][i+1] = dp_1[j][i]
        elif N[i+1] =='0':
            dp_1[j][i+1] = dp_1[j][i]
        else:

            dp_0[j][i+1] += dp_1[j][i]

print(dp_0[K][len(N)-1]+dp_1[K][len(N)-1])

Buggy python submission (verdict: Runtime Error):
from scipy.misc import comb
N=input()
K=int(input())
if len(N)<K:
    print(0)
    exit()
if K !=1:
    ans = 0
elif len(N)<2:
    print(int(N))
    exit()
else:
    ans = 9
for i in range(2,len(N)):
    ans += 9*comb(i-1,K-1)*(9**(K-1))
ans += (int(N[0])-1)*comb(len(N)-1,K-1)*9**(K-1)
if K==1:
    ans += 1
elif K==2:
    ans += 9*(len(N)-2)+int(N[1])
else:
    ans += int(N[2])+(len(N)-3)*9+(int(N[1])-1)*(len(N)-2)*9+comb(len(N)-2,2)*81
print(ans)

Fixed submission:
N=input()
K=int(input())
dp_0 = [[0]*(len(N)) for i in range(K+1)]
dp_1 = [[0]*(len(N)) for i in range(K+1)]
dp_0[0][0]=1
dp_0[1][0]=int(N[0])-1
dp_1[1][0]=1
for i in range(len(N)-1):
    for j in range(K+1):
        if j==K:
            dp_0[j][i+1] += dp_0[j][i]
        elif j==0:
            dp_0[j][i+1] =dp_0[j][i]
            dp_0[j+1][i+1] += dp_0[j][i]*9
        else:
            dp_0[j][i+1] += dp_0[j][i]
            dp_0[j+1][i+1] += dp_0[j][i]*9
        if j != K and N[i+1] != '0':
            dp_0[j+1][i+1] += (int(N[i+1])-1)*dp_1[j][i]
            dp_0[j][i+1] += dp_1[j][i]
            dp_1[j+1][i+1] = dp_1[j][i]
        elif N[i+1] =='0':
            dp_1[j][i+1] = dp_1[j][i]
        else:

            dp_0[j][i+1] += dp_1[j][i]

print(dp_0[K][len(N)-1]+dp_1[K][len(N)-1])
Buggy python submission (verdict: Time Limit Exceeded):
H,N=map(int,input().split(' '))
Magics = [list(map(int,input().split(' '))) for i in range(N)]
dp=[float('inf')]*(H+1)
dp[0]=0
for i in range(H+1):
    for a,b in Magics:
        if i+a<=H:
            dp[i+a]=min(dp[i+a],dp[i]+b)
        else:
            dp[H]=min(dp[H],dp[i]+b)
print(dp[H])

Fixed submission:
H,N=map(int,input().split(' '))
Magics = [list(map(int,input().split(' '))) for i in range(N)]
dp=[float('inf')]*(H+1)
dp[H]=0
for i in range(H,-1,-1):
    for a,b in Magics:
        if 0<=i-a<=H:
            dp[i-a]=min(dp[i-a],dp[i]+b)
        else:
            dp[0]=min(dp[0],dp[i]+b)
print(dp[0])

Buggy python submission (verdict: Time Limit Exceeded):
H,N=map(int,input().split(' '))
Magics = [list(map(int,input().split(' '))) for i in range(N)]
dp=[float('inf')]*(H+1)
dp[H]=0
for i in range(H,-1,-1):
    for a,b in Magics:
        if 0<=i-a<=H:
            dp[i-a]=min(dp[i-a],dp[i]+b)
        else:
            dp[0]=min(dp[0],dp[i]+b)
print(dp[0])

Fixed submission:
H,N=map(int,input().split(' '))
Magics = [list(map(int,input().split(' '))) for i in range(N)]
dp=[float('inf')]*(H+1)
dp[H]=0
for i in range(H,-1,-1):
    for a,b in Magics:
        if 0<=i-a<=H:
            dp[i-a]=min(dp[i-a],dp[i]+b)
        else:
            dp[0]=min(dp[0],dp[i]+b)
print(dp[0])
Buggy python submission (verdict: Runtime Error):
S,T=input().split('')
print(T+S)

Fixed submission:
S,T=input().split(' ')
print(T+S)
Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input().split(' '))
if sum(a.b.c) >=22:
    print('bust')
else:
    print('win')

Fixed submission:
a=list(map(int,input().split(' ')))
if sum(a) >=22:
    print('bust')
else:
    print('win')
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=[[tuple(map(int,input().split(' ')))for j in range(int(input()))] for i in range(N)]
say_map=[[-1 for i in range(N)] for j in range(N)]
ans = 0
for n,i in enumerate(A):
    for j,k in i:
        say_map[n][j-1]=k
for i in range(2**N):
    i_bin=format(i,'0{}b'.format(N))
    flg = True
    tmp = 0
    for n,j in enumerate(i_bin):
        j = int(j)
        if j == 1:
            tmp += 1
            for k,l in zip(i_bin,say_map[n]):
                if (int(k)==0 and l==1) or (int(k)==1 and l ==0):
                    flg=False
                    break
            if not flg:
                tmp = 0
                break
    ans = max(ans,tmp)
print(ans)

Fixed submission:
N=int(input())
A=[[tuple(map(int,input().split(' ')))for j in range(int(input()))] for i in range(N)]
say_map=[[-1 for i in range(N)] for j in range(N)]
ans = 0
for n,i in enumerate(A):
    for j,k in i:
        say_map[n][j-1]=k
for i in range(2**N):
    i_bin=format(i,'0{}b'.format(N))
    flg = True
    tmp = 0
    for n,j in enumerate(i_bin):
        j = int(j)
        if j == 1:
            tmp += 1
            for k,l in zip(i_bin,say_map[n]):
                if (int(k)==0 and l==1) or (int(k)==1 and l ==0):
                    flg=False
                    break
            if not flg:
                tmp = 0
                break
    ans = max(ans,tmp)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(lambda x: format(int(x), '060b'), input().split(' ')))
mod = 10 ** 9 + 7
one = [0]*60
ans = 0
for i in A:
    for n, j in enumerate(i[::-1]):
        if int(j):
            one[n] += 1
for n,i in enumerate(one):
    ans = (ans + 2**n *i*(N-i))%mod
print(ans)

Fixed submission:
N = int(input())
A = ''.join(list(map(lambda x: format(int(x), '060b'), input().split(' '))))
mod = 10 ** 9 + 7
ans = 0
for n in range(60):
    one = A[59-n::60].count('1')
    ans = (ans + 2**n *one*(N-one))%mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(lambda x: format(int(x), '060b'), input().split(' ')))
mod = 10 ** 9 + 7
one = [0]*60
ans = 0
for i in A:
    for n, j in enumerate(i[::-1]):
        if int(j):
            one[n] += 1
for n,i in enumerate(one):
    ans = (ans + 2**n *i*(N-i))%mod
print(ans)

Fixed submission:
N = int(input())
A = ''.join(list(map(lambda x: format(int(x), '060b'), input().split(' '))))
mod = 10 ** 9 + 7
ans = 0
for n in range(60):
    one = A[59-n::60].count('1')
    ans = (ans + 2**n *one*(N-one))%mod
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a=list(map(int,input().split(' ')))
mod = 10**9+7
ans = 1
color=[1,0,0]
g = 0
for i in a[1:]:
    cnt = 0
    for n,j in enumerate(color):
        if i==0 and j ==0:
            color[n]+=1
            cnt = 1
            break
        elif i==j:
            cnt += 1
            if cnt == 1:
                color[n]+=1
    ans *= cnt
    ans %= mod
for i in color:
    if i >0:
        g += 1
if g ==1:
    print(ans*3%mod)
else:
    print(ans*6%mod)

Fixed submission:
M_1,D_1 = map(int,input().split())
M_2,D_2 = map(int,input().split())
if M_1 != M_2:
  print(1)
else:
  print(0)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N = int(input())
A = list(map(int, input().split(' ')))
mod = 10 ** 9 + 7
c = np.array([0, 0, 0])
ans = 1
for i in A:
    ans *= sum(c == i)
    if i == c[0]:
        c[0] += 1
    elif i == c[1]:
        c[1] += 1
    else:
        c[2] += 1
    ans %= mod
print(ans)


Fixed submission:
N = int(input())
A = list(map(int, input().split(' ')))
mod = 10 ** 9 + 7
c = [0, 0, 0]
ans = 1
for i in A:
    ans *= c.count(i)
    if i == c[0]:
        c[0] += 1
    elif i == c[1]:
        c[1] += 1
    else:
        c[2] += 1
    ans %= mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N = int(input())
A = list(map(int,input().split(' ')))
mod = 10**9+7
high = 0
mid = 0
low = 0
ans = 1
for i in A:
    ans *= sum(np.array([high, mid, low]) == i)
    if i == high:
        high += 1
    elif i == mid:
        mid += 1
    else:
        low += 1
    ans %= mod
print(ans)


Fixed submission:
N = int(input())
A = list(map(int, input().split(' ')))
mod = 10 ** 9 + 7
c = [0, 0, 0]
ans = 1
for i in A:
    ans *= c.count(i)
    if i == c[0]:
        c[0] += 1
    elif i == c[1]:
        c[1] += 1
    else:
        c[2] += 1
    ans %= mod
print(ans)
Buggy python submission (verdict: Runtime Error):
from numpy.linalg import solve
mod = 10**9+7
x,y=map(int,input().split(' '))
left = [[1,2],
        [2,1]]
right = [x,y]

A=solve(left,right)
ax,ay=float(A[0]),float(A[1])
if (not float.is_integer(ax) or not float.is_integer(ay)):
    print(0)
    exit()
ax,ay=int(ax),int(ay)
fac=[0 for i in range(ax+ay+1)]
inv=[0 for i in range(ax+ay+1)]
finv=[0 for i in range(ax+ay+1)]
fac[0] = 1
fac[1] = 1
finv[0]=1
finv[1]=1
inv[1] = 1
for i in range(2,ax+ay+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
ans = fac[ax+ay]*(finv[ax]*finv[ay])
ans %= mod
print(int(ans))

Fixed submission:
from numpy.linalg import solve
mod = 10**9+7
x,y=map(int,input().split(' '))
left = [[1,2],
        [2,1]]
right = [x,y]

A=solve(left,right)
ax,ay=float(A[0]),float(A[1])
if not 0.5 <= y/x <= 2:
    print(0)
    exit()
if not float.is_integer(ax) or not float.is_integer(ay):
    print(0)
    exit()
ax,ay=int(ax),int(ay)
fac=[0 for i in range(ax+ay+1)]
inv=[0 for i in range(ax+ay+1)]
finv=[0 for i in range(ax+ay+1)]
fac[0] = 1
fac[1] = 1
finv[0]=1
finv[1]=1
inv[1] = 1
for i in range(2,ax+ay+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
ans = fac[ax+ay]*(finv[ax]*finv[ay])
ans %= mod
print(int(ans))
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
def main():
    n=int(input())
    l=sorted(list(map(int,input().split(' '))))
    ans = 0
    for n,i in enumerate(l):
        for m,j in enumerate(l[n+1:]):
                ans +=bisect.bisect_left(l,i+j) - bisect.bisect_right(l,abs(i-j))
                if abs(i-j)<i<i+j:
                    ans -=1
                if abs(i-j)<j<i+j:
                    ans -=1
    print(ans//3)
if __name__ == '__main__':
    main()


Fixed submission:
import bisect
def main():
    n=int(input())
    l=sorted(list(map(int,input().split(' '))))
    ans = 0
    for n,i in enumerate(l):
        for m,j in enumerate(l[n+1:]):
                ans +=bisect.bisect_left(l,i+j) - bisect.bisect_right(l,abs(i-j))
                if abs(i-j)<i<i+j:
                    ans -=1
                if abs(i-j)<j<i+j:
                    ans -=1
    print(ans//3)
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
def main():
    n=int(input())
    l=sorted(list(map(int,input().split(' '))))
    ans = 0
    for n,i in enumerate(l):
        for m,j in enumerate(l):
            if n!=m:
                ans +=bisect.bisect_left(l,i+j) - bisect.bisect_right(l,abs(i-j))
                if abs(i-j)<i<i+j:
                    ans -=1
                if abs(i-j)<j<i+j:
                    ans -=1
    print(ans//6)
if __name__ == '__main__':
    main()


Fixed submission:
import bisect
def main():
    n=int(input())
    l=sorted(list(map(int,input().split(' '))))
    ans = 0
    for n,i in enumerate(l):
        for m,j in enumerate(l[n+1:]):
                ans +=bisect.bisect_left(l,i+j) - bisect.bisect_right(l,abs(i-j))
                if abs(i-j)<i<i+j:
                    ans -=1
                if abs(i-j)<j<i+j:
                    ans -=1
    print(ans//3)
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
def main():
    n,m,l=map(int,input().split(' '))
    g=[[float('inf')if i != j  else 0  for i in range(n)] for j in range(n)]
    for i in range(m):
        a,b,c=map(int,input().split(' '))
        if c <=l:
            g[a-1][b-1]=c
            g[b-1][a-1]=c
    q=int(input())
    q_list=[tuple(map(int,input().split(' '))) for i in range(q)]
    for k in range(n):
        for i in range(n):
            for j in range(i,n):
                g[i][j]= min(g[i][j],g[i][k]+g[k][j])
                g[j][i]=g[i][j]

    for i in range(n):
        for j in range(n):
            if g[i][j]<=l:
                if g[i][j] != 0:
                    g[i][j] = 1
                else:
                    g[i][j] = 0
            else:
                g[i][j] = float('inf')

    for k in range(n):
        for i in range(n):
            for j in range(n):
                g[i][j] = min(g[i][j],g[i][k]+g[k][j])
    for i,j in q_list:
        if g[i-1][j-1] != float('inf'):
            print(g[i-1][j-1]-1)
        else:
            print(-1)


if __name__ == '__main__':
    main()


Fixed submission:
import bisect
def main():
    n,m,l=map(int,input().split(' '))
    g=[[float('inf')if i != j  else 0  for i in range(n)] for j in range(n)]
    for i in range(m):
        a,b,c=map(int,input().split(' '))
        if c <=l:
            g[a-1][b-1]=c
            g[b-1][a-1]=c
    q=int(input())
    q_list=[tuple(map(int,input().split(' '))) for i in range(q)]
    for k in range(n):
        for i in range(n):
            for j in range(i,n):
                g[i][j]= min(g[i][j],g[i][k]+g[k][j])
                g[j][i]=g[i][j]

    for i in range(n):
        for j in range(n):
            if g[i][j]<=l:
                if g[i][j] != 0:
                    g[i][j] = 1
                else:
                    g[i][j] = 0
            else:
                g[i][j] = float('inf')

    for k in range(n):
        for i in range(n):
            for j in range(n):
                g[i][j] = min(g[i][j],g[i][k]+g[k][j])
    for i,j in q_list:
        if g[i-1][j-1] != float('inf'):
            print(g[i-1][j-1]-1)
        else:
            print(-1)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
from collections import deque

N, Q = map(int, input().split(' '))
tree = [[] for i in range(N + 1)]
for i in range(N - 1):
    a, b = map(int, input().split(' '))
    tree[a].append([a, b])
    tree[b].append([b, a])
val = [0] * (N + 1)
for i in range(Q):
    p, x = map(int, input().split(' '))
    val[p] += x
ans = [-1] * (N + 1)
ans[1] = val[1]
bfs = deque(tree[1])
while bfs:
    p, n = bfs.popleft()
    if ans[n] == -1:
        ans[n] = val[n] + ans[p]
        for i in tree[n]:
            bfs.append(i)
for i in ans[1:-1]:
    print(i,'',end="")
print(ans[-1])

Fixed submission:
def main():
    a=int(input())
    s=input()
    if a >= 3200:
        print(s)
    else:
        print('red')

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def mian():
    a,b=map(jnt,input().split(' '))
    print(max(a+b,a-b,a*b))
if __name__ == '__main__':
    main()

Fixed submission:
def main():
    a,b = map(int,input().split(' '))
    print(max(a+b,a-b,a*b))
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import heapq as hq
def main():
    n,m = map(int,input().split(' '))
    w = [list(map(int,input().split(' '))) for i in range(n)]
    w=sorted(w)
    ans = 0
    l = []
    tmp = 0
    for i in range(1,m+1):
        while w and w[0][0] <= i:
            hq.heappush(l,-w.pop(0)[1])
        if l:
            ans -=hq.heappop(l)
    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
import heapq as hq
def main():
    n,m = map(int,input().split(' '))
    w = [list(map(int,input().split(' '))) for i in range(n)]
    w=sorted(w,reverse=True)
    ans = 0
    l = []
    tmp = 0
    for i in range(1,m+1):
        while w and w[-1][0] <= i:
            hq.heappush(l,-w.pop()[1])
        if l:
            ans -=hq.heappop(l)
    print(ans)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    l,r = map(int,input().split(' '))
    tmp = 2019
    if l//2019 < r//2019:
        print(0)
    else:
        for i in range(l,r):
            if tmp > (i*(i+1))%2019:
                tmp = (i*(i+1))%2019
                if tmp == 0:
                    print(i,i+1)
        print(tmp)

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    n,a,b = map(int,input().split(' '))
    print(min(int(n*a),b))

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    l,r = map(int,input().split(' '))
    tmp = 2019
    if l//2019 < r//2019:
        print(0)
    else:
        for i in range(l,r):
            if tmp > (i*(i+1))%2019:
                tmp = (i*(i+1))%2019
                if tmp == 0:
        print(tmp)

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    l,r = map(int,input().split(' '))
    tmp = 2019
    if l//2019 < r//2019:
        print(0)
    else:
        for i in range(l,r):
            for j in range(i+1,r+1):
                if tmp > (i*j)%2019:
                    tmp = (i*j)%2019
        print(tmp)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
mod = 10**9+7

def fac(n):
    fac = [1]*(n+1)
    fac[0] = 1
    fac[1] = 1
    for i in range(1,n+1):
        fac[i] = fac[i-1]*i%mod
    return fac

def main():
    n,m=map(int,input().split(' '))
    fact = fac(n)
    check = 0
    pattern = 1
    a = [0]
    a_list = []
    tmp = -1
    for i in range(m):
        an = int(input())
        a.append(an)
    for i in range(m):
        a_list.append(a[i+1]-a[i]-1)
    a_list.append(n-a[-1]-1)
    if a_list[0] ==0:
        a_list.pop(0)
    for i in a_list:
        tmp = 0
        for j in range(i):
            if i - 2*j >=0:
                tmp +=(fact[(i-j)]/fact[j]/fact[i-2*j])%mod
        pattern *= tmp
        pattern %= mod

    print(int(pattern))

if __name__=='__main__':
    main()

Fixed submission:
def main():
    n=list(map(int,input().split(' ')))
    n_sorted = sorted(n)
    print(n_sorted[0]+n_sorted[1])

if __name__=='__main__':
    main()