Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02862 (python)

Fixed submission:
X,Y=map(int,input().split())
if X<Y:
    X,Y=Y,X
mod=10**9+7

N=min(X,Y)
factl=[1]
for i in range(1,N+1):
    factl.append(factl[-1]*i%mod)
invl=[pow(factl[-1],mod-2,mod)]
for i in range(N,0,-1):
    invl.append(invl[-1]*i%mod)
invl.reverse()
def Comb(a,b):
    return factl[a]*invl[a-b]*invl[b]%mod

d=X-Y
if (Y-d)%3!=0 or Y-d<0:
    print(0)
    exit()
x,y=d+(Y-d)//3,(Y-d)//3

print(Comb(x+y,y))

Buggy submission (verdict: Runtime Error):
X,Y=map(int,input().split())
if X<Y:
    X,Y=Y,X
mod=10**9+7

N=min(X,Y)
factl=[1]
for i in range(1,N+1):
    factl.append(factl[-1]*i%mod)
invl=[pow(factl[-1],mod-2,mod)]
for i in range(N,0,-1):
    invl.append(invl[-1]*i%mod)
invl.reverse()
def Comb(a,b):
    return factl[a]*invl[a-b]*invl[b]%mod

x,y=0,0
while X>=3 and Y>=3:
    x+=1
    y+=1
    X-=3
    Y-=3
if X==0 and Y==0:
    pass
elif X//Y == 2 and X%Y==0:
    x+=Y
else:
    print(0)
    exit()

print(Comb(x+y,y))
Problem p03038 (python)

Fixed submission:
n,m=map(int,input().split())
a=sorted(map(int,input().split()))
b=sorted([list(map(int,input().split())) for i in range(m)],key=lambda x:x[1])[::-1]
i=0
for num,v in b:
	for j in range(num):
		if i<n and a[i]<v:
			a[i]=v
			i+=1
		else:
			print(sum(a))
			exit()
else:
	print(sum(a))

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=sorted(map(int,input().split()))
b=sorted([list(map(int,input().split())) for i in range(m)],key=lambda x:x[1])[::-1]
i=0
for num,v in b:
	for j in range(num):
		if a[i]<v and i<n:
			a[i]=v
			i+=1
		else:
			print(sum(a))
			exit()
else:
	print(sum(a))

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=sorted([list(map(int,input().split())) for i in range(m)],key=lambda x:x[1])[::-1]
i=0
for num,v in b:
	for j in range(num):
		if a[i]<v and i<n:
			a[i]=v
			i+=1
		else:
			print(sum(a))
			exit()
else:
	print(sum(a))
Problem p03207 (python)

Fixed submission:
n=int(input())
l=[int(input()) for i in range(n)]
print(sum(l)-max(l)//2)

Buggy submission (verdict: Runtime Error):
n=int(imput())
l=[int(input()) for i in range(n)]
print(sum(l)-max(l)//2)
Problem p03209 (python)

Fixed submission:
l = [1]
p = [1]
N, X = map(int, input().split())
for i in range(N):
    l.append(l[i] * 2 + 3)
    p.append(p[i] * 2 + 1)


def calc(n, x):
    if l[n] <= x:
        return p[n]
    if x == 0 or x == 1:
        return 0
    if x <= l[n] // 2:
        return calc(n - 1, x - 1)
    elif x == l[n] // 2 + 1:
        return p[n - 1] + 1
    else:
        return p[n - 1] + 1 + calc(n - 1, x - (l[n - 1] + 2))

print(calc(N, X))

Buggy submission (verdict: Runtime Error):
l=[1]
p=[1]
N,X=map(int,input().split())
for i in range(N):
    l.append(l[i]*2+3)
    p.append(p[i]*2+1)
def calc(n,x):
    if n==0 and x==1:
        return 1
    if x==0 or x==1:
        return 0
    if x<=l[n]//2:
        return calc(n-1,x-1)
    elif x==l[n]//2+1:
        return p[n-1]+1
    else:
        return p[n-1]+1+calc(n-1,x-(l[n-1]+2))

print(calc(N,X))
Problem p03253 (python)

Fixed submission:
from functools import reduce
n,m=map(int,input().split())
dic=dict()
p=2
while m>=p*p:
    if m%p==0:
        dic[p]=0
        while m%p==0:
            dic[p]+=1
            m//=p
    p+=1
if m!=1:
    if m not in dic.keys():
        dic[m]=0
    dic[m]+=1
def comb(a,b):
    p=1
    for i in range(a,a-b,-1):
        p*=i
    for i in range(2,b+1):
        p//=i
    return p
l=[comb(i+n-1,i) if 1 not in dic.keys() else 1 for i in dic.values() ]
ans=1
for i in l:
    ans=ans*i%1000000007
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
from functools import reduce
sys.setrecursionlimit(1000000)
n,m=map(int,input().split())
dic=dict()
sqrm=int(m**0.5)
for i in range(2,sqrm+1):
    if m%i==0:dic[i]=0
    while m%i==0:
        dic[i]+=1
        m//=i
if m>sqrm:dic[m]=1
ans=1
def comb(a,b):
    p=1
    for i in range(a,a-b,-1):
        p*=i
    for i in range(2,b+1):
        p//=i
    return p
l=[comb(i+n-1,i) for i in dic.values()]
print(reduce(lambda x,y: x*y%1000000007, l))
Problem p03286 (python)

Fixed submission:
n=int(input())
ans=[]
if n%2==1:
    ans.append("1")
    n-=1
else:ans.append("0")
n//=2
while n!=0:
    ans.append("1") if n%2==1 else ans.append("0")
    n//=-2
print("".join(ans[::-1]))

Buggy submission (verdict: Runtime Error):
n=int(input())
absn=abs(n)
sign=[1,-1]

b,cnt=1,0
while b<absn*2:
    b*=2
    cnt+=1
ans=[]
while cnt >= 0:
    sub=n-b*sign[cnt%2]
    if abs(sub)<abs(b) or abs(sub)<=abs(n):
        ans.append("1")
        n=sub
    else:
        ans.append("0")
    b//=2
    cnt-=1
for i in range(3):
    if ans[i]=="1":break
print("".join(ans[i::]))
Problem p03835 (python)

Fixed submission:
k,s=map(int,input().split())
cnt=0
for i in range(s+1):
    if i>k:
        break
    cnt+= max(0,min(i+k,s)-max(s-k,i)+1)
print(cnt)

Buggy submission (verdict: Runtime Error):
k,s=map(int,input().split())
cnt=0
for i in range(s+1):
	for j in range(i,s+12 2):
		if i<=k and j-i<=k and s-j<=k:
			cnt+=1
print(cnt)
Problem p02736 (python)

Fixed submission:
import sys
INF = 10 ** 9
MOD = 10 ** 9 + 7
from collections import deque
sys.setrecursionlimit(100000000)

fact2 = [0] * 1000011
def cnt2(n):
    if n%2 == 1:
        return 0
    else:
        fact2[n] = 1 + fact2[n//2]
        return fact2[n]

factorial = [0,0]
for i in range(2,1000010):
    factorial.append(factorial[-1] + cnt2(i))

def nck(n,k):
    return factorial[n] - factorial[k] - factorial[n - k]

def nxor(x,n):
    if n > 0:
        return 0
    else:
        return x


def main():
    n = int(input())
    a = [int(i) - 1 for i in list(input())]
    
    cumxor = 0
    amod = [i%2 for i in a]
    for i in range(n):
        cumxor ^= nxor(amod[i],nck(n - 1,i))
    
    if cumxor == 1:
        ans = 1
    else:
        if 1 in a:
            ans = 0
        else:
            cumxor = 0
            adiv = [i//2 for i in a]
            for i in range(n):
                cumxor ^= nxor(adiv[i],nck(n - 1,i))
            if cumxor == 0:
                ans = 0
            else:
                ans = 2
    
    print(ans)

if __name__=='__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
INF = 10 ** 9
MOD = 10 ** 9 + 7
from collections import deque
sys.setrecursionlimit(100000000)

fact2 = [0] * 1000011
def cnt2(n):
    if n%2 == 1:
        return 0
    else:
        fact2[n] = 1 + fact2[n//2]
        return fact2[n]

factorial = [0,0]
for i in range(2,1000010):
    factorial.append(factorial[-1] + cnt2(i))

def nck(n,k):
    return factorial[n] - factorial[k] - factorial[n - k]

def nxor(x,n):
    if n > 0:
        return 0
    else:
        return x


def main():
    n = int(input())
    a = [int(i) - 1 for i in list(input())]
    
    cumxor = 0
    amod = [i%2 for i in a]
    for i in range(n):
        cumxor ^= nxor(amod[i],nck(n - 1,i))
    
    if cumxor == 1:
        ans = 1
    else:
        if 1 in a:
            ans = 0
        else:
            cumxor = 0
            adiv = [a//2 for i in a]
            for i in range(n):
                cumxor ^= nxor(adiv[i],nck(n - 1,i))
            if cumxor == 0:
                ans = 0
            else:
                ans = 2
    
    print(ans)

if __name__=='__main__':
    main()
Problem p02754 (python)

Fixed submission:
def main():
    n,a,b=map(int,input().split())
    if a==0:
        ans=0
    else:
        t=n//(a+b)
        if t==0:
            ans=min(a,n)
        else:
            ans=a*t+min(n%(t*(a+b)),a)
    print(ans)

if __name__=='__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n,a,b=map(int,input().split())
    t=n//(a+b)
    ans=a*t+min(n%(t*(a+b)),a)
    print(ans)

if __name__=='__main__':
    main()
Problem p02829 (python)

Fixed submission:
a=int(input())
b=int(input())

if a==1 and b==2:
  print(3)
elif a==1 and b==3:
  print(2)
elif a==2 and b==1:
  print(3)
elif a==2 and b==3:
  print(1)
elif a==3 and b==1:
  print(2)
elif a==3 and b==2:
  print(1)

Buggy submission (verdict: Runtime Error):
a=int(input())
b=int(input())

if a==1 and b==2:
  print(3)
elif a==1 and b==3:
  print(2)
elif a==2 and b==1:
  pirnt(3)
elif a==2 and b==3:
  print(1)
elif a==3 and b==1:
  print(2)
else:
  print(1)
Problem p02859 (python)

Fixed submission:
r=int(input())
print(r**2)

Buggy submission (verdict: Runtime Error):
#n**p mod m を計算する(デフォルト引数は10**9+7)
def n_ruijyou_p(n,p,m=10**9+7):
    bin_p=format(p,'b')
    ans=1
    nruijyou2i=n
    
    if bin_p[0]=='1':
       ans=ans*nruijyou2i%m

    for i in range(1,len(bin_p)):
        nruijyou2i=(nruijyou2i)**2
        print(nruijyou2i)
        if bin_p[i]=='1':
            ans=ans*nruijyou2i%m
           
    return ans 
  
x,y=map(int,input().split())
print(n_ruijyou_p(x,y))

Buggy submission (verdict: Runtime Error):
#互いに素なa,bについて、a*x+b*y=1の一つの解
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]

# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
def mod_inv(a,m):
    if a%m!=0:
      x = extgcd(a,m)[0]
      return (m+x%m)%m
      

#nCk mod m を計算する(デフォルトの引数は10**9+7)
def c_mod(n,k,m=10**9+7):
  res = 1
  for i in range(1,n+1):
      if (i%m)!=0:
        res = res*i%m
      else:
        res=res/i%m
  for i in range(1,k+1):
      if (i%m)!=0:
        res = res*mod_inv(i,m)%m
      else:
        res=res/i%m
  for i in range(1,n-k+1):
      if (i%m)!=0:
        res = res*mod_inv(i,m)%m
      else:
        res=res/i%m
  return res


x,y=map(int,input().split())
if (2*x-y)%3==0 and (2*y-x)%3==0 and (2*y-x)>0 and (2*x-y)>0 :
  l=int((2*x-y)/3)
  k=int((2*y-x)/3)
  ans=c_mod(l+k,k)

else:
  ans=0
print(ans)
Problem p02897 (python)

Fixed submission:
n=int(input())
ans=(n/2+(n%2)*0.5)/n
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
A=[[int(i)] for i in input().split()]

for i in range(n):
  A[i].append(i)
A=sorted(A, key=lambda x:x[0])
B=[A[i][1]+1 for i in range(n)]

print(*B)
Problem p02925 (python)

Fixed submission:
import sys
INF = 10 ** 9
MOD = 10 ** 9 + 7
from collections import deque
sys.setrecursionlimit(100000000)
input = sys.stdin.readline
from copy import deepcopy 

MAXN = 1005
MAXV = MAXN * (MAXN - 1)//2
G = [[] for _ in range(MAXV)]

id = [[-1] * MAXN for _ in range(MAXN)]
def toId(i,j):
    if i > j:
        i,j = j,i
    return id[i][j]


finished = [0] * MAXV
dp = [-1] * MAXV
def dfs(v):
    if dp[v] != -1:
        if finished[v] == 0:
            return -1
        return dp[v]
    dp[v] = 0
    for e in G[v]:
        res = dfs(e)
        if res == -1:
            return -1
        dp[v] = max(dp[v],res + 1)
    finished[v] = 1
    return dp[v]


def main():
    n = int(input())
    a = [[int(i) - 1 for i in input().split()] for _ in range(n)]

    v = 0
    for i in range(n):
        for j in range(i + 1,n):
            id[i][j] = v
            v += 1
    
    for i in range(n):
        for j in range(n - 1):
            a[i][j] = toId(i,a[i][j])
        for j in range(n - 2):
            G[a[i][j]].append(a[i][j + 1])
    
    ans = 0
    for i in range(v):
        res = dfs(i)
        if res == -1:
            ans = -1
            break
        ans = max(ans,dfs(i) + 1)
    
    print(ans)

if __name__=='__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
INF = 10 ** 9
MOD = 10 ** 9 + 7
from collections import deque
sys.setrecursionlimit(100000000)

n = int(input())
pair = []
for i in range(n):
    for j in range(i + 1,n):
        pair.append((i,j))

G = {i:set() for i in pair}
inedge = {i:0 for i in pair}
for i in range(n):
    a = [int(i) - 1 for i in input().split()]
    for j in range(n - 2):
        if i <= a[j] and i <= a[j + 1]:
            G[(i,a[j])].add((i,a[j + 1]))
            inedge[(i,a[j + 1])] += 1
        elif i <= a[j] and i > a[j + 1]:
            G[(i,a[j])].add((a[j + 1],i))
            inedge[(a[j + 1],i)] += 1
        elif i > a[j] and i <= a[j + 1]:
            G[(a[j],i)].add((i,a[j + 1]))
            inedge[(i,a[j + 1])] += 1
        else:
            G[(a[j],i)].add((a[j + 1],i))
            inedge[(a[j + 1],i)] += 1
    
visited = {i:0 for i in pair}
finished = {i:0 for i in pair}
print(G)

flag = 1
def dfs(node): #サイクルの検出用
    global flag
    visited[i] = 1
    for e in G[node]:
        if finished[node]:
            continue
        if visited[node] and finished[node] == 0:
            flag = 0
            return
        dfs(e)
    if flag == 0:
        return
    finished[node] = 1

dfs((0,1))
    
if flag == 1:
    st = deque()
    dist = {i:-1 for i in pair}
    for i in pair:
        if inedge[i] == 0:
            st.append(i)
            dist[i] = 1
        
    while len(st):
        node = st.pop()
        for e in G[node]:
            dist[e] = max(dist[e],dist[node] + 1)
            inedge[e] -= 1
            if inedge[e] == 0:
                st.append(e)  
    print(dist) 
    print(max(dist.values()))
else:
    print(-1)
Problem p02984 (python)

Fixed submission:
def main():
  n=int(input())
  rain=[int(i) for i in input().split()]
  
  test=0
  for i in range(n):
    test=rain[i]-test
  ans=test
  
  fall=[0]*n
  fall[0]=test
  for i in range(n-1):
    tmp=rain[i]-fall[i]//2
    fall[i+1]=2*tmp
  
  print(*fall)
if __name__=='__main__':
  main()

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

n=int(input())
rain=np.array([int(i)*2 for i in input().split()])

a=np.eye(n,dtype=np.int64)
for i in range(n-1):
  a[i][i+1]=1
a[-1][0]=1

ans=np.linalg.solve(a,rain)
ans=ans.astype(np.int64)
print(*ans)
Problem p02990 (python)

Fixed submission:
n,k=map(int,input().split())
mod=10**9+7

#x**t%mod
def pow(x,t):
    if t==0:
        return 1
    a=pow(x,t>>1)
    return a*a*(x**(t&1))%mod

#n!%mod
fact=[0]*(n+1)
fact[0]=1
for i in range(1,n+1):
    fact[i]=fact[i-1]*i
    fact[i]%=mod

#1/n!%mod
ifact=[0]*(n+1)
ifact[n]=pow(fact[n],mod-2)
for i in range(n,0,-1):
    ifact[i-1]=ifact[i]*i
    ifact[i-1]%=mod


def nCr(n,r):
    if r<0 or r>n:
        return 0
    return fact[n]*ifact[r]*ifact[n-r]%mod


for i in range(1,k+1):
  ans=nCr(k-1,i-1)*nCr(n-k+1,i)
  ans%=mod
  print(ans)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
mod=10**9+7

#x**t%mod
def pow(x,t):
    if t==0:
        return 1
    a=pow(x,t>>1)
    return a*a*(x**(t&1))%mod

#n!%mod
fact=[0]*n
fact[0]=1
for i in range(1,n):
    fact[i]=fact[i-1]*i
    fact[i]%=mod

#1/n!%mod
ifact=[0]*n
ifact[n-1]=pow(fact[n-1],mod-2)
for i in range(n-1,0,-1):
    ifact[i-1]=ifact[i]*i
    ifact[i-1]%=mod


def nCr(n,r):
    if r<0 or r>n:
        return 0
    return fact[n]*ifact[r]*ifact[n-r]%mod


for i in range(1,k+1):
  ans=nCr(k-1,i-1)*nCr(n-k+1,i)
  ans%=mod
  print(ans)
Problem p03013 (python)

Fixed submission:
n,m=map(int,input().split())
broken=[int(input()) for i in range(m)]
mod=10**9+7

is_broken=[True]*(n+1)
for i in range(m):
  is_broken[broken[i]]=False
   
dp=[0]*(n+1)
dp[0]=1
if is_broken[1]:
  dp[1]=dp[0]
  
for i in range(2,n+1):
    if is_broken[i]:
       dp[i]=dp[i-1]+dp[i-2]
       dp[i]%=mod
    else:
      dp[i]=0
      
print(dp[n])

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
broken=[int(input()) for i in range(m)]
mod=10**9+7

is_broken=[True]*(n+1)
for i in range(m):
  is_broken[broken[i]]=False
   
dp=[0]*(n+1)

if  is_broken[1]:
  dp[1],dp[2]=1,2
else:
  if is_broken[2]:
    dp[2]=1

if n>=2:
  for i in range(3,n+1):
    if is_broken[i]:
       dp[i]=dp[i-1]+dp[i-2]
       dp[i]%=mod
    else:
      dp[i]=0
      
print(dp[n])

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
broken=[int(input()) for i in range(m)]
mod=10**9+7

is_broken=[True]*(n+1)
for i in range(m):
  is_broken[broken[i]]=False
   
dp=[0]*(n+1)

if  is_broken[1]:
  dp[1],dp[2]=1,2
else:
  if is_broken[2]:
    dp[2]=1

if n>=2:
  for i in range(3,n+1):
    if i in broken:
      dp[i]=0
    
    elif  is_broken[i-1] and is_broken[i-2]:
      dp[i]=dp[i-1]+dp[i-2]
      dp[i]%=mod
    
    elif is_broken[i-1]:
      dp[i]=dp[i-1]
      dp[i]%=mod
    
    elif is_broken[i-2]:
      dp[i]=dp[i-2]
      dp[i]%=mod
    
    else:
      dp[i]=0
print(dp[n])

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
broken=[int(input()) for i in range(m)]
mod=10**9+7

is_broken=[True]*(n+1)
for i in range(m):
  is_broken[broken[i]]=False
   
dp=[0]*(n+1)
if  is_broken[1]:
  dp[1],dp[2]=1,2
else:
  if is_broken[2]:
    dp[2]=1

for i in range(3,n+1):
  if i in broken:
    dp[i]=0
    
  elif  is_broken[i-1] and is_broken[i-2]:
    dp[i]=dp[i-1]+dp[i-2]
    dp[i]%=mod
    
  elif is_broken[i-1]:
    dp[i]=dp[i-1]
    dp[i]%=mod
    
  elif is_broken[i-2]:
    dp[i]=dp[i-2]
    dp[i]%=mod
    
  else:
    dp[i]=0
    
print(dp[n])

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
broken=[int(input()) for i in range(m)]
mod=10**9+7

dp=[0]*(n+1)
if 1 not in broken:
  dp[1],dp[2]=1,2
else:
  if 2 not in broken:
    dp[2]=1

for i in range(3,n+1):
  if i in broken:
    dp[i]=0
    
  elif  i-1 not in broken and i-2 not in broken:
    dp[i]=dp[i-1]+dp[i-2]
    dp[i]%=mod
    
  elif i-1 not in broken:
    dp[i]=dp[i-1]
    dp[i]%=mod
    
  elif i-2 not in broken:
    dp[i]=dp[i-2]
    dp[i]%=mod
    
  else:
    dp[i]=0
print(dp[n])
Problem p03041 (python)

Fixed submission:
n,k=map(int,input().split())
s=list(input())
if s[k-1]=='A':
  s[k-1]='a'
elif s[k-1]=='B':
  s[k-1]='b'
else:
  s[k-1]='c'
print(''.join(s))

Buggy submission (verdict: Runtime Error):
from collections import deque,defaultdict
n=int(input())
routes=[tuple(map(int,input().split())) for i in range(n-1)]

edges=defaultdict(list)
for v1,v2,dist in routes:
  edges[v1-1].append([v2-1,dist])

ans=[0]*n
q=deque([0])
while q:
  v=q.popleft()
  if ans[v]==0:
    color=[0,1]
  else:
    color=[1,0]
  for edge in edges[v]:
    v2=edge[0]
    dist=edge[1]
    q.append(v2)
    if dist%2==1:
      ans[v2]=color[1]
    else:
      ans[v2]=color[0]
print(*ans,sep='\n')
Problem p03045 (python)

Fixed submission:
def main():
    import sys
    input=sys.stdin.readline
    sys.setrecursionlimit(1000000000)
    n,m=map(int,input().split())
    G=[[] for _ in range(n)]
    for _ in range(m):
        x,y,z=map(int,input().split())
        x-=1
        y-=1
        G[x].append(y)
        G[y].append(x)
    
    visited=[True]*n
    def dfs(i):
        visited[i]=False
        for e in G[i]:
            if visited[e]:
                dfs(e)
    
    cnt=0
    for i in range(n):
        if visited[i]:
            cnt+=1
            dfs(i)
    
    print(cnt)  

if __name__=='__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    import sys
    input=sys.stdin.readline
    n,m=map(int,input().split())
    G=[[] for _ in range(n)]
    for _ in range(m):
        x,y,z=map(int,input().split())
        x-=1
        y-=1
        G[x].append(y)
        G[y].append(x)
    
    visited=[True]*n
    def dfs(i):
        visited[i]=False
        for e in G[i]:
            if visited[e]:
                dfs(e)
    
    cnt=0
    for i in range(n):
        if visited[i]:
            cnt+=1
            dfs(i)
    
    print(cnt)  

if __name__=='__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    import sys
    input=sys.stdin.readline
    n,m=map(int,input().split())
    G=[[] for _ in range(n)]
    for _ in range(m):
        x,y,z=map(int,input().split())
        x-=1
        y-=1
        G[x].append(y)
        G[y].append(x)
    
    visited=[True]*n
    def dfs(i):
        for e in G[i]:
            if visited[e]:
                visited[e]=False
                dfs(e)
    
    cnt=0
    for i in range(n):
        if visited[i]:
            cnt+=1
            dfs(i)
    
    print(cnt)  

if __name__=='__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    import sys
    input=sys.stdin.readline
    n,m=map(int,input().split())
    G=[[] for _ in range(n)]
    for i in range(m):
        x,y,z=map(int,input().split())
        x-=1
        y-=1
        G[x].append(y)
        G[y].append(x)
    
    visited=[True]*n
    def dfs(i):
        for e in G[i]:
            if visited[e]:
                visited[e]=False
                dfs(e)
    
    cnt=0
    for i in range(n):
        if visited[i]:
            cnt+=1
            dfs(i)
    
    print(cnt)  

if __name__=='__main__':
    main()
Problem p03286 (python)

Fixed submission:
def main():
  n=int(input())
  ans=[]
  if n==0:
    print(0)
  while n!=0:
    s=n%2
    ans.append(s)
    if s==0:
      n//=(-2)
    else:
      n=(n-1)//(-2)
  ans=ans[::-1]
  print(''.join([str(bit) for bit in ans]))
if __name__=='__main__':
  main()

Buggy submission (verdict: Runtime Error):
MOD = 10 ** 9 + 7
INF = 10 ** 10
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from math import gcd

def main():
    n = int(input())
    s = []
    if n == 0:
        print('0')
        return

    while n != 0:
        if n%2 == 0:
            s.append('0')
            n //= -2
        else:
            s.append('1')
            n -= 1
            n //= -2
    print(''.join(s[::-1]))

if __name__ =='__main__':
    main()
Problem p03634 (python)

Fixed submission:
import heapq
def dijkstra(V, edges, s):
    inf=float('inf')

    dist=[inf]*V
    dist[s]=0
    
    que=[[0,s]]
    heapq.heapify(que) #最小値を管理 [dist[i],i]となる要素

    while  que:
        p=heapq.heappop(que) #距離が最小のものを取り出す
        dis=p[0]
        v=p[1]
        if dist[v] <dis:
            continue
        for edge in edges[v]:
            to_v=edge[0]
            cost=edge[1]
        
            if dist[to_v] > dist[v] + cost:
                dist[to_v]=dist[v]+cost
                heapq.heappush(que,[dist[to_v], to_v])
    
    return dist

def main():
    n=int(input())
    edges=[[] for _ in range(n)]
    for i in range(n-1):
        a,b,c=map(int,input().split())
        a-=1
        b-=1
        edges[a].append([b,c])
        edges[b].append([a,c])
    q,k=map(int,input().split())
    k-=1
   
    dist=dijkstra(n,edges,k)
    for i in range(q):
        x,y=map(int,input().split())
        x-=1
        y-=1
        print(dist[x]+dist[y])
if __name__=='__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    import sys
    input=sys.stdin.readline
    n=int(input())
    edges=[[] for _ in range(n)]
    for i in range(n-1):
        a,b,c=map(int,input().split())
        a-=1
        b-=1
        edges[a].append([b,c])
        edges[b].append([a,c])
    q,k=map(int,input().split())
    k-=1
    
    dist=[10**9+1]*n
    dist[k]=0
    
    def dfs(s,before=-1):
       for edge in edges[s]:
           to=edge[0]
           c=edge[1]
           if to!=before:
               dist[to]=dist[s]+c
               dfs(to,s) 
              
    dfs(k)
    for i in range(q):
        x,y=map(int,input().split())
        x-=1
        y-=1
        print(dist[x]+dist[y])
if __name__=='__main__':
    main()
Problem p03986 (python)

Fixed submission:
x=list(input())
n=len(x)

stack=['T',x[0]]
for i in range(1,n):
  if x[i]=='S':
    stack.append('S')
  else:
    if stack[-1]=='S':
      stack.pop()
    else:
      stack.append('T')
print(len(stack)-1)

Buggy submission (verdict: Runtime Error):
x=list(input())
n=len(x)

stack=[x[0]]
for i in range(1,n):
  if x[i]=='S':
    stack.append('S')
  else:
    if stack[-1]=='S':
      stack.pop()
    else:
      stack.append('T')
print(len(stack))