Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
def main():
    def pre(n,mod):
        an=[1]*(n+1)
        a=1
        for i in range(1,n+1):
            a=(a*i)%mod
            an[i]=a
        b=pow(a,mod-2,mod)
        bs=[1]*(n+1)
        bs[n]=b
        for i in range(n,1,-1):
            b=b*i%mod
            bs[i-1]=b
        return an,bs

    n,k=map(int,input().split())
    a=sorted(list(map(int,input().split())))
    mod=10**9+7
    an,bs=pre(n,mod)
    ans=0
    for i in range(k,n+1):
        for j in range(0,n-i+1):
            s=a[i+j-1]-a[j]
            s=(s*an[i-2]*bs[k-2]*bs[i-k])%mod
            ans=(ans+s)%mod
    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
a='abcdefghijklmnopqrstuvwxyz'
s=input()
cnt=0
while s!=a[cnt]:
	cnt+=1
print(a[cnt+1])
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
cnt=0
acc=0
ac={}
for i in range(m):
	p,s= map(str,input().split())
	if ac[p]==0:
		if s=='AC':
			acc+=1
			ac[p]=1
		else:
			cnt+=1
print(acc,cnt)

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

def main():
    n,m=map(int,input().split())
    w=[0]*(n+1)
    a=[0]*(n+1)
    for i in range(m):
        p,s=map(str,input().split())
        p=int(p)
        if a[p]==0:
            if s=='WA':
                w[p]+=1
            else:
                a[p]=1
    wa=0
    for i in range(1,n+1):
        wa=wa+a[i]*w[i]
    print(sum(a),wa)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
n,m= map(int,input().split())
cnt=0
acc=0
ac=[0]*n
for i in range(m):
	p,s= map(str,input().split())
	if ac[int(p)]==0:
		if s=='AC':
			acc+=1
			ac[int(p)]=1
		else:
			cnt+=1
print(acc,cnt)

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

def main():
    n,m=map(int,input().split())
    w=[0]*(n+1)
    a=[0]*(n+1)
    for i in range(m):
        p,s=map(str,input().split())
        p=int(p)
        if a[p]==0:
            if s=='WA':
                w[p]+=1
            else:
                a[p]=1
    wa=0
    for i in range(1,n+1):
        wa=wa+a[i]*w[i]
    print(sum(a),wa)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
n,m= map(int,input().split())
cnt=0
acc=0
ac=[0]*n
for i in range(m):
	p,s= map(str,input().split())
	if ac[int(p)]==0:
		if s=='AC':
			acc+=1
			ac[int(p)]=1
		else:
			cnt+=1
print(acc,cnt)

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

def main():
    n,m=map(int,input().split())
    w=[0]*(n+1)
    a=[0]*(n+1)
    for i in range(m):
        p,s=map(str,input().split())
        p=int(p)
        if a[p]==0:
            if s=='WA':
                w[p]+=1
            else:
                a[p]=1
    wa=0
    for i in range(1,n+1):
        wa=wa+a[i]*w[i]
    print(sum(a),wa)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

def main():
    n,m=map(int,input().split())
    a=sorted(list(map(int,input().split())))
    a.reverse()
    l,r=2*a[-1],2*a[0]
    x=(l+r)//2
    while l+1<r:
        cnt=0
        for A in a:
            for B in a:
                if A+B>=x:
                    cnt+=1
                else:
                    break
        if cnt>=m:
            l=x
        else:
            r=x
        x=(l+r)//2
    s,cnt=0,0
    for A in a:
        for B in a:
            if A+B>=l:
                cnt+=1
                s+=A+B
            else:
                break
    print(s+(m-cnt)*l)
    
if __name__ == '__main__':
    main()

Fixed submission:
s,t=map(str,input().split())
print(t+s)
Buggy python submission (verdict: Runtime Error):
import math
a,b=map(int,input().split())
print(int((a*b)/math.gcd(a, b)))

Fixed submission:
import fractions
a,b=map(int,input().split())
print(int((a*b)/fractions.gcd(a, b)))
Buggy python submission (verdict: Runtime Error):
n=int(input())
if n%2==1:
	print(0)
else:
	n2=n/2
	ans=0
	while n2>0:
		n2=n2//5
		ans+=n2
    print(int(ans))

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

def main():
    n=int(input())
    cnt=5
    ans=0
    if n%2==0:
        n=n//2
        while cnt<=n:
            ans+=n//cnt
            cnt*=5
    print(ans)                
    
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
n=int(input())
n2=0
if n%2==1:
	print(0)
else:
	n2=n/2
	ans=0
	while n2>0:
		n2=n2//5
		ans+=n2
print(int(ans))

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

def main():
    n=int(input())
    cnt=5
    ans=0
    if n%2==0:
        n=n//2
        while cnt<=n:
            ans+=n//cnt
            cnt*=5
    print(ans)                
    
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
n=int(input())
n2=0
if n%2==1:
	print(0)
else:
	n2=int(n/2)
	ans=0
	while n2>0:
		n2=int(n2//5)
		ans+=n2
print(ans)

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

def main():
    n=int(input())
    cnt=5
    ans=0
    if n%2==0:
        n=n//2
        while cnt<=n:
            ans+=n//cnt
            cnt*=5
    print(ans)                
    
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
n=int(input())
if n%2==1:
	print(0)
else:
	n2=int(n/2)
	ans=0
	while n2>0:
		n2=int(n2/5)
		ans+=n2
print(ans)

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

def main():
    n=int(input())
    cnt=5
    ans=0
    if n%2==0:
        n=n//2
        while cnt<=n:
            ans+=n//cnt
            cnt*=5
    print(ans)                
    
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
mod=10**9+7
def axora(a,b):
  x=(a^b)%mod
  return x

n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(n-1):
  for j in range(i+1,n):
    ans=(ans+axora(a[i],a[j]))%mod
print(ans)

Fixed submission:
import numpy as np
n = int(input())
a=list(map(int,input().split()))
ma=len(bin(max(a)))-2
b=np.array(a)
mod=10**9+7
ans=0
for i in range(ma):
  one=np.count_nonzero((b&1)==1)
  zero=n-one
  ans+=(one*zero*(2**i))%mod
  b=b//2
print(ans%mod)
Buggy python submission (verdict: Runtime Error):
N=int(input())
if int((N//1.08)*1.08)==N:
  print(int(N//1.08))
elif int((N//1.08+1)*1.08)==N:
  print(int(N//1.08+1))
else:
  print(':(')

Fixed submission:
m1,d1=map(int,input().split())
m2,d2=map(int,input().split())
if m1==m2:
  print('0')
else:
  print('1')
Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    n=int(input())
    s=list(input())
    l=[]
    ans=0
    for i in range(n-2):
        for j in range(i+1,n-1):
            x=s[i]+s[j]
            if x in l:
                continue
            else:
                l.append(x)
                ans+=len(set(s[j+1:]))
    print(ans)


if __name__ == '__main__':
    resolve()

Fixed submission:
N=int(input())
S=str(input())
X=[0]*1000
cnt=0
for i in range(10):
  a=S.find(str(i))
  if a==-1:
    continue
  else:
    for j in range(10):
      b=S[a+1:].find(str(j))
      if b==-1:
        continue
      else:
        for k in range(10):
          c=S[a+b+2:].find(str(k))
          if c==-1:
            continue
          else:
            cnt+=1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=str(input())
X=[0]*1000
for i in range(N-2):
  for j in range(i+1,N-1):
    for k in range(j+1,N):
      X[int(S[i])*100+int(S[j])*10+int(S[k])]=1
print(sum(X))

Fixed submission:
N=int(input())
S=str(input())
X=[0]*1000
cnt=0
for i in range(10):
  a=S.find(str(i))
  if a==-1:
    continue
  else:
    for j in range(10):
      b=S[a+1:].find(str(j))
      if b==-1:
        continue
      else:
        for k in range(10):
          c=S[a+b+2:].find(str(k))
          if c==-1:
            continue
          else:
            cnt+=1
print(cnt)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
c=[0]*n
c[0]=3
cnt=1
for i in a:
  cnt=cnt*c[i]%1000000007
  c[i]-=1
  c[i+1]+=1

print(cnt)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
c=[0]*(n+1)
c[0]=3
cnt=1
for i in a:
  cnt=cnt*c[i]%1000000007
  c[i]-=1
  c[i+1]+=1
print(cnt)

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
c=[0]*n
c[0]=3
cnt=1
for i in a:
  cnt*=c[i]
  c[i]-=1
  c[i+1]+=1

print(cnt%1000000007)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
c=[0]*(n+1)
c[0]=3
cnt=1
for i in a:
  cnt=cnt*c[i]%1000000007
  c[i]-=1
  c[i+1]+=1
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
A=list(map(int,input().split()))
cnt=0
for i in range(N):
  Alen=0
  Asum=0
  for j in range(i,N):
    if i==j:
      Alen=1
      Asum=A[j]
    else:
      Alen+=1
      Asum+=A[j]
    if Asum%K==Alen:
      cnt+=1
print(cnt)

Fixed submission:
from collections import defaultdict
d=defaultdict(int)
N,K=map(int,input().split())
A=[0]+list(map(int,input().split()))
S=[None]*(N+1)
S[0]=0
cnt=0
d[0]=1
for i in range(1,N+1):
  S[i]=(S[i-1]+A[i]-1)%K
for i in range(1,N+1):
  if i-K>=0:
    d[S[i-K]]-=1
  cnt+=d[S[i]]
  d[S[i]]+=1
print(cnt)
Buggy python submission (verdict: Runtime Error):

s=input()
n=len(s)
ans=[0]*(n+1)
m=0
for i in range(1,n+1):
	if s[i]=='<':
		ans[i]=ans[i-1]+1
	else:
		ans[i]=ans[i-1]-1
	m=min(m,ans[i])
print(sum(ans)-m*n)
		


Fixed submission:
s=str(input())
sl=len(s)+1
l,r=[0]*sl,[0]*sl
ss=[0]*sl
lcnt,rcnt=0,0
for i in range(sl):
  if i==0:
    l[0]=0
    r[sl-1]=0
  else:
    if s[i-1]=="<":
      lcnt+=1
    else:
      lcnt=0
    if s[sl-i-1]==">":
      rcnt+=1
    else:
      rcnt=0
    l[i]=lcnt
    r[sl-i-1]=rcnt
for i in range(sl):
  ss[i]=max(l[i],r[i])
print(sum(ss))
Buggy python submission (verdict: Runtime Error):
n=int(input())
2.i=int(n**0.5)
3.while i<n:
4.  if n%i==0:
5.    break
6.  else:
7.    i+=1
8.if i==n:
9.  print(i-1)
10.else:
11.  print(int(i+n/i)-2)

Fixed submission:
a,b=map(int,input().split())
if a>=10 or b>=10:
  print(-1)
else:
  print(a*b)
Buggy python submission (verdict: Runtime Error):
n=int(input())
2.i=int(n**0.5)
3.while i<n:
4.  if n%i==0:
5.    break
6.  else:
7.    i+=1
8.if i==n:
9.  print(i-1)
10.else:
11.  print(int(i+n/i)-2)


Fixed submission:
n=int(input())
i=int(n**0.5)+1
while i>0:
  if n%i==0:
    break
  else:
    i-=1
if i==n:
  print(i-1)
else:
  print(int(i+n/i)-2)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
i=int(n**0.5)
while i<n:
  if n%i==0:
    break
  else:
    i+=1
if i==n:
  print(i-1)
else:
  print(int(i+n/i)-2)

Fixed submission:
n=int(input())
i=int(n**0.5)+1
while i>0:
  if n%i==0:
    break
  else:
    i-=1
if i==n:
  print(i-1)
else:
  print(int(i+n/i)-2)
Buggy python submission (verdict: Runtime Error):
import math
a,b,x=map(int,input().split())
c=2*x/(a*b)
if (b*a**2)/2<x:
  print(90-math.atan(a/(2*(b-x/(a**2))))/(2*math.pi)*360)
else:
  print(math.atan(b/c)/(2*math.pi)*360)

Fixed submission:
import math
a,b,x=map(int,input().split())
v=a*a*b
if x>v/2:
  print(math.degrees(math.atan(2*(b-x/(a**2))/a)))
else:
  print(math.degrees(math.atan(a*b*b/(2*x))))
Buggy python submission (verdict: Runtime Error):
7
5 0 7 8 3 3 2

Fixed submission:
n=int(input())
d=list(map(int,input().split()))
s=[0]*int(n*(n-1)/2)
cnt=0
for i in range(n):
  for j in range(i+1,n):
    s[cnt]=d[i]*d[j]
    cnt+=1
print(sum(s))

Buggy python submission (verdict: Runtime Error):
n=int(input())
d=list(map(int,input().split()))
s=[0]*n
cnt=0
for i in range(n):
  for j in range(i+1,n):
    s[cnt]=d[i]*d[j]
    cnt+=1
print(sum(s))

Fixed submission:
n=int(input())
d=list(map(int,input().split()))
s=[0]*int(n*(n-1)/2)
cnt=0
for i in range(n):
  for j in range(i+1,n):
    s[cnt]=d[i]*d[j]
    cnt+=1
print(sum(s))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
from fractions import gcd

def main():
    a,b=map(int,input().split())
    g=gcd(a,b)
    prime=[i for i in range(g+1)]
    for i in range(2,int(g**0.5)+1):
        cnt=2
        if prime[i]>0:
            while cnt*i<=g:
                prime[cnt*i]=0
                cnt+=1
    ans=1
    for i in prime:
        if i<=1:
            continue
        else:
            if g%i==0:
                ans+=1
    print(ans)
    
if __name__ == '__main__':
    main()

Fixed submission:
import sys
input = sys.stdin.readline
from fractions import gcd
import collections

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

def main():
    a,b=map(int,input().split())
    g=gcd(a,b)
    print(len(set(prime_factorize(g)))+1)

if __name__ == '__main__':
    main()

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

def main():
    a,b=map(int,input().split())
    g=gcd(a,b)
    prime=[i for i in range(g+1)]
    for i in range(2,int(g**0.5)+1):
        cnt=2
        if prime[i]>0:
            while cnt*i<=g:
                prime[cnt*i]=0
                cnt+=1
    ans=1
    for i in prime:
        if i<=1:
            continue
        else:
            if g%i==0:
                ans+=1
    print(ans)
    
if __name__ == '__main__':
    main()

Fixed submission:
import sys
input = sys.stdin.readline
from fractions import gcd
import collections

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

def main():
    a,b=map(int,input().split())
    g=gcd(a,b)
    print(len(set(prime_factorize(g)))+1)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
I=list(map(int,open(0).read().split()))
n,k,q=I[:3]
a=I[3:]
p=np.array([k]*n)
for i in a:
    p-=1
    p[i-1]+=1
for i in p:
    if i<=0:
        print('No')
    else:
        print('Yes')

Fixed submission:
I=list(map(int,open(0).read().split()))
n,k,q=I[:3]
a=I[3:]
p=[0]*n
for i in a:
    p[i-1]+=1
for i in p:
    if i<=q-k:
        print('No')
    else:
        print('Yes')
Buggy python submission (verdict: Runtime Error):
I=list(map(int,open(0).read().split()))
n,m=I[:2]
a=I[2:]
for i in range(m):
    a.sort()
    a[m-1]=a[m-1]//2
print(int(sum(a)))

Fixed submission:
import heapq
n,m=map(int,input().split())
a = list(map(lambda x: int(x)*(-1), input().split()))
heapq.heapify(a)
for i in range(m):
    ma=heapq.heappop(a)
    heapq.heappush(a,(-1)*((-ma)//2))
print(-sum(a))
Buggy python submission (verdict: Runtime Error):
def main():
    n,q=map(int,input().split())
    ab=[[] for _ in range(n)]
    for i in range(n-1):
        a,b=map(int,input().split())
        ab[a-1].append(b-1)
        ab[b-1].append(a-1)
    visit=[False]*n
    cnt=[0]*n
    for i in range(q):
        p,x=map(int,input().split())
        cnt[p-1]+=x

    def solve(s,x):
        visit[s]=True
        cnt[s]+=x
        x=cnt[s]
        for i in ab[s]:
            if visit[i]:
                continue
            solve(i,x)
        return
    
    solve(0,0)
    print(*cnt, sep=' ')

if __name__ == '__main__':
    main()

Fixed submission:
import sys
from collections import deque
input = sys.stdin.readline

def main():
    n,q=map(int,input().split())
    t=[[] for _ in range(n+1)]
    cnt=[0]*(n+1)
    tf=[0]*(n+1)
    for i in range(n-1):
        a,b=map(int,input().split())
        t[a].append(b)
        t[b].append(a)
    for i in range(q):
        p,x=map(int,input().split())
        cnt[p]+=x
    d=deque()
    d.append(1)
    tf[1]=1
    while d:
        chk=d.popleft()
        for i in t[chk]:
            if tf[i]==1:
                continue
            else:
                d.append(i)
                tf[i]=1
                cnt[i]+=cnt[chk]
    print(' '.join(map(str,cnt[1:])))

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=[sorted(input()) for i in range(n)]
s.sort()
cnt=0
while len(s)>1:
  k=s.count(s[0])
  if k==1:
    continue
  else:
    cnt+=int(k*(k-1)/2)
  del s[:k]
print(cnt)

Fixed submission:
n=int(input())
A={}
for i in range(n):
  s=str(sorted(input()))
  if s in A.keys():
    A[s]+=1
  else:
    A[s]=1
ans=0
for i in list(A.values()):
  ans+=int(i*(i-1)/2)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=[sorted(input()) for i in range(n)]
s.sort()
cnt=0
k=0
for i in range(n-1):
  for j in range(i+1,n):
    for k in range(10):
      if s[i][k]!=s[j][k]:
        break
      elif k==9:
        cnt+=1
print(cnt)

Fixed submission:
n=int(input())
A={}
for i in range(n):
  s=str(sorted(input()))
  if s in A.keys():
    A[s]+=1
  else:
    A[s]=1
ans=0
for i in list(A.values()):
  ans+=int(i*(i-1)/2)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def chk(A,B):
  nL=len(A)
  ans=0
  for i in range(nL):
    if A[i]!=B[i]:
      break
    elif i==nL-1:
      ans=1
  return ans
n=int(input())
s=[sorted(input()) for i in range(n)]
s.sort()
cnt=0
k=0
for i in range(n-1):
  for j in range(i+1,n):
    k=chk(s[i],s[j])
    if k==0:
      break
    else:
      cnt+=k
print(cnt)

Fixed submission:
n=int(input())
A={}
for i in range(n):
  s=str(sorted(input()))
  if s in A.keys():
    A[s]+=1
  else:
    A[s]=1
ans=0
for i in list(A.values()):
  ans+=int(i*(i-1)/2)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def chk(A,B):
  nL=len(A)
  if A[0]==B[0]:
    if nL==1:
      return 1
    else:
      return chk(A[1:],B[1:])
  else:
    return 0
n=int(input())
s=[sorted(input()) for i in range(n)]
s.sort()
cnt=0
k=0
for i in range(n-1):
  for j in range(i+1,n):
    k=chk(s[i],s[j])
    if k==0:
      break
    else:
      cnt+=k
print(cnt)

Fixed submission:
n=int(input())
A={}
for i in range(n):
  s=str(sorted(input()))
  if s in A.keys():
    A[s]+=1
  else:
    A[s]=1
ans=0
for i in list(A.values()):
  ans+=int(i*(i-1)/2)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def chk(A,B):
  nL=len(A)
  if A[0]==B[0]:
    if nL==1:
      return 1
    else:
      return chk(A[1:],B[1:])
  else:
    return 0
n=int(input())
s=[sorted(input()) for i in range(n)]
s.sort()
cnt=0
for i in range(n-1):
  for j in range(i+1,n):
    cnt+=chk(s[i],s[j])
print(cnt)

Fixed submission:
n=int(input())
A={}
for i in range(n):
  s=str(sorted(input()))
  if s in A.keys():
    A[s]+=1
  else:
    A[s]=1
ans=0
for i in list(A.values()):
  ans+=int(i*(i-1)/2)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque
input = sys.stdin.readline

def main():
    n,m=map(int,input().split())
    ab=[list(map(int,input().split())) for _ in range(n)]
    ab.sort()
    c=[0]*n
    ans=0
    for i in range(1,m+1):
        mb=0
        mnum=-1
        for j in range(n):
            if ab[j][0]<=i:
                if mb<ab[j][1] and c[j]==0:
                    mb=ab[j][1]
                    mnum=j
            else:
                break
        ans+=mb
        if mnum!=-1:
            c[mnum]=1
    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
import sys
from heapq import heappush, heappop
input = sys.stdin.readline

def main():
    n,m=map(int,input().split())
    ab=[]
    for i in range(n):
        a,b=map(int,input().split())
        if a>m:
            continue
        ab.append((a,b))
    ab.sort(reverse=True)    
    q=[]
    ans=0
    for i in range(1,m+1):
        while ab and ab[-1][0]<=i:
            a,b=ab.pop()
            heappush(q,-b)
        if q:
            b=-heappop(q)
            ans+=b
    print(ans)

if __name__ == '__main__':
    main()

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

def main():
    n,m=map(int,input().split())
    ab=[list(map(int,input().split())) for _ in range(n)]
    ab.sort()
    c=[0]*n
    ans=0
    for i in range(1,m+1):
        mb=0
        mnum=-1
        for j in range(n):
            if ab[j][0]<=i:
                if mb<ab[j][1] and c[j]==0:
                    mb=ab[j][1]
                    mnum=j
            else:
                break
        ans+=mb
        if mnum!=-1:
            c[mnum]=1
    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
import sys
from heapq import heappush, heappop
input = sys.stdin.readline

def main():
    n,m=map(int,input().split())
    ab=[]
    for i in range(n):
        a,b=map(int,input().split())
        if a>m:
            continue
        ab.append((a,b))
    ab.sort(reverse=True)    
    q=[]
    ans=0
    for i in range(1,m+1):
        while ab and ab[-1][0]<=i:
            a,b=ab.pop()
            heappush(q,-b)
        if q:
            b=-heappop(q)
            ans+=b
    print(ans)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
INF=10**30
def Belman_Ford(s,N,Edge):
    dist=[INF]*N
    neg=[False]*N
    dist[s]=0
    for i in range(N-1):
        for f,t,c in Edge:
            if dist[t]>dist[f]+c and dist[f]!=INF:
                dist[t]=min(dist[t],dist[f]+c)
    for i in range(N):
        for f,t,c in Edge:
            if dist[t]>dist[f]+c and dist[f]!=INF:
                dist[t]=dist[f]+c
                neg[t]=True
            if neg[f]:
                neg[t]=True
    return dist,neg
                
N,M,P=map(int,input().split())
Edge=[]
for i in range(M):
    a,b,c=map(int,input().split())
    Edge.append((a-1,b-1,-(c-P)))
dist,neg=Belman_Ford(0,N,Edge)

if(neg[N-1]):
    print(-1)
else:
    ans=-dist[N-1]
    print(max(0,ans))

Fixed submission:
INF=10**30
def Belman_Ford(s,N,Edge):
    dist=[INF]*N
    neg=[False]*N
    dist[s]=0
    for i in range(N-1):
        for f,t,c in Edge:
            if dist[t]>dist[f]+c and dist[f]!=INF:
                dist[t]=min(dist[t],dist[f]+c)
    for i in range(N):
        for f,t,c in Edge:
            if dist[t]>dist[f]+c and dist[f]!=INF:
                dist[t]=dist[f]+c
                neg[t]=True
            if neg[f]:
                neg[t]=True
    return dist,neg
                
N,M,P=map(int,input().split())
Edge=[]
for i in range(M):
    a,b,c=map(int,input().split())
    Edge.append((a-1,b-1,-(c-P)))
dist,neg=Belman_Ford(0,N,Edge)

if(neg[N-1]):
    print(-1)
else:
    ans=-dist[N-1]
    print(max(0,ans))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from heapq import heappush, heappop
#input = sys.stdin.readline

def main():
    s=list(input())
    n=len(s)
    mod=10**9+7
    dp=[[0]*13 for _ in range(n)]
    if s[0]=='?':
        dp[0]=[1,1,1,1,1,1,1,1,1,1,0,0,0]
    else:
        dp[0][int(s[0])]=1
    for i in range(1,n):
        for j in range(13):
            if s[i]=='?':
                for k in range(10):
                    x=(j*10+k)%13
                    dp[i][x]+=dp[i-1][j]
                    dp[i][x]%=mod
            else:
                x=(j*10+int(s[i]))%13
                dp[i][x]+=dp[i-1][j]
                dp[i][x]%=mod
    print(dp[n-1][5])

if __name__ == '__main__':
    main()

Fixed submission:
import sys
from heapq import heappush, heappop
#input = sys.stdin.readline

def main():
    s=list(input())
    n=len(s)
    mod=10**9+7
    dp=[[0]*13 for _ in range(n)]
    if s[0]=='?':
        dp[0]=[1,1,1,1,1,1,1,1,1,1,0,0,0]
    else:
        dp[0][int(s[0])]=1
    for i in range(1,n):
        for j in range(13):
            if s[i]=='?':
                for k in range(10):
                    x=(j*10+k)%13
                    dp[i][x]+=dp[i-1][j]
                    dp[i][x]%=mod
            else:
                x=(j*10+int(s[i]))%13
                dp[i][x]+=dp[i-1][j]
                dp[i][x]%=mod
    print(dp[n-1][5])

if __name__ == '__main__':
    main()