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

Fixed submission:
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict
from math import gcd
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())
    d=defaultdict(lambda:[0,0])
    zz=0
    for _ in range(N):
        a,b=map(int,input().split())
        g=gcd(a,b)
        if g==0:
            zz+=1
        else:
            a//=g
            b//=g
            if a<0:
                a*=-1
                b*=-1
            if a*b>0:
                d[(a,b)][0]+=1
            elif a*b<0:
                d[(-b,a)][1]+=1
            else:
                if a:
                    d[(1,0)][0]+=1
                else:
                    d[(1,0)][1]+=1
    l=[]
    other=0
    for k,a in d.items():
        if a[0] and a[1]:
            l.append((a[0],a[1]))
        else:
            other+=sum(a)
    ans=pow(2,other,MOD)
    ans%=MOD
    dp=[[0]*2 for _ in range(len(l)+1)]
    dp[0][0]=1
    for i in range(len(l)):
        dp[i+1][0]=dp[i][0]+dp[i][1]
        dp[i+1][1]=(dp[i][0]+dp[i][1])*(pow(2,l[i][0],MOD)+pow(2,l[i][1],MOD)-2)
        dp[i+1][0]%=MOD
        dp[i+1][1]%=MOD
    ans*=sum(dp[-1])
    ans-=1
    ans+=zz
    ans%=MOD
    print(ans)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict
from math import gcd
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())
    d=defaultdict(lambda:[0,0])
    for _ in range(N):
        a,b=map(int,input().split())
        g=gcd(a,b)
        a//=g
        b//=g
        if a<0:
            a*=-1
            b*=-1
        if a*b>0:
            d[(a,b)][0]+=1
        elif a*b<0:
            d[(-b,a)][1]+=1
        else:
            d[0][0]+=1
    l=[]
    zero=0
    other=0
    for k,a in d.items():
        if k==0:
            zero=a[0]
        else:
            if a[0] and a[1]:
                l.append((a[0],a[1]))
            else:
                other+=sum(a)
    ans=pow(2,other,MOD)*(zero+1)
    ans%=MOD
    dp=[[0]*2 for _ in range(len(l)+1)]
    dp[0][0]=1
    for i in range(len(l)):
        dp[i+1][0]=dp[i][0]+dp[i][1]
        dp[i+1][1]=(dp[i][0]+dp[i][1])*(pow(2,l[i][0],MOD)+pow(2,l[i][1],MOD)-2)
        dp[i+1][0]%=MOD
        dp[i+1][1]%=MOD
    ans*=sum(dp[-1])
    ans-=1
    ans%=MOD
    print(ans)

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

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 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()
Problem p02815 (python)

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 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()
Problem p02881 (python)

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 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)
Problem p02912 (python)

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 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)
Problem p02915 (python)

Fixed submission:
N = int(input())
print(N**3)

Buggy submission (verdict: Runtime Error):
 N = int(input())
 print(N**3)
Problem p03013 (python)

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

def main():
    N,M=map(int,input().split())
    a=[int(input()) for i in range(M)]
    dp=[1]*(N+1)
    if M!=0:
        dp[1]=0 if a[0]==1 else 1
        for i in a:
            dp[i]=0
    for i in range(1,N):
        if dp[i+1]!=0:
            dp[i+1] = (dp[i]+dp[i-1]) % 1000000007
    print(dp[N])


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
a=[int(input()) for i in range(M)]
dp=[1]*(N+2)
dp[1]=0 if a[0]==1 else 1
for i in a:
    dp[i]=0
for i in range(1,N):
    if dp[i+1]!=0:
        dp[i+1] = (dp[i]+dp[i-1]) % 1000000007
print(dp[N])

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

def main():
    N,M=map(int,input().split())
    a=[int(input()) for i in range(M)]
    dp=[1]*(N+2)
    dp[1]=0 if a[0]==1 else 1
    for i in a:
        dp[i]=0
    for i in range(1,N):
        if dp[i+1]!=0:
            dp[i+1] = (dp[i]+dp[i-1]) % 1000000007
    print(dp[N])


if __name__ == '__main__':
    main()

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

def main():
    N,M=map(int,input().split())
    a=[int(input()) for i in range(M)]
    dp=[1]*(N+1)
    dp[1]=0 if a[0]==1 else 1
    for i in a:
        dp[i]=0
    for i in range(1,N):
        if dp[i+1]!=0:
            dp[i+1] = (dp[i]+dp[i-1]) % 1000000007
    print(dp[N])


if __name__ == '__main__':
    main()

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

def main():
    N,M=map(int,input().split())
    a=[int(input()) for i in range(M)]
    dp=[1]*(N+1)
    dp[1]=0 if a[0]==1 else 1
    for i in a:
        dp[i]=0
    for i in range(1,N):
        if dp[i+1]!=0:
            dp[i+1] = (dp[i]+dp[i-1]) % 1000000007
    print(dp[N])


if __name__ == '__main__':
    main()

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

def main():
    N,M=map(int,input().split())
    a=[int(input()) for i in range(M)]
    dp=[1]*(N+1)
    dp[1]=0 if a[0]==1 else 1
    for i in a:
        dp[i]=0
    for i in range(1,N):
        if dp[i+1]!=0:
            dp[i+1]=dp[i]+dp[i-1]
    print(dp[N]%1000000007)


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

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

def main():
    s=input()
    s2=list(s.replace('BC','D'))
    N=len(s2)
    ans=0
    c=0
    for i in range(N):
        if s2[i]=='A':
            c+=1
        elif c!=0 and s2[i]=='D':
            ans+=c
        else:
            c=0
    print(ans)

if __name__ == '__main__':
    main()

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

def main():
    def checkABC(x):
        if s[x]=='A' and s[x+1]=='B' and s[x+2]=='C':
            s[x],s[x+1],s[x+2]='B','C','A'
            return True
        else:
            return False
    
    s=list(input())
    N=len(s)
    i=0
    ans=0
    while True:
        if i >= N-2:
            break
        if checkABC(i) == True:
            if i!=0 and s[i-1]=='A':
                i-=2
            else:
                i+=1
            ans+=1
        while True:
            i+=1
            if s[i] == 'A':
                break
    print(ans)
        
        

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

Fixed submission:
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict
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,M=map(int,input().split())
    d=defaultdict(int)
    x=2
    while M>1:
        if M%x==0:
            d[x]+=1
            M//=x
        else:
            x+=1
    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(10**6,MOD)
    
    def COM(n, k, MOD=MOD):
        if n<k or n<0 or k<0:
            return 0
        return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD
    
    ans=1
    for v in d.values():
        ans*=COM(N-1+v,v,MOD)
        ans%=MOD
    print(ans)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict
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,M=map(int,input().split())
    d=defaultdict(int)
    x=2
    while M>1:
        if M%x==0:
            d[x]+=1
            M//=x
        else:
            x+=1
    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*2,MOD)
    
    def COM(n, k, MOD=MOD):
        if n<k or n<0 or k<0:
            return 0
        return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD
    
    ans=1
    for v in d.values():
        ans*=COM(N-1+v,v,MOD)
        ans%=MOD
    print(ans)

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

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():
    S=list(input())
    A,C,Q=[0]*(len(S)+1),[0]*(len(S)+1),[0]*(len(S)+1)
    l_B=[]
    l_Q=[]
    q=0
    for i in range(len(S)):
        A[i+1]=A[i]+(S[i]=='A')
        C[i+1]=C[i]+(S[i]=='C')
        Q[i+1]=Q[i]+(S[i]=='?')
        if S[i]=='?':
            q+=1
            l_Q.append(i)
        if S[i]=='B':
            l_B.append(i)
    ans=0
    pow3q=pow(3,q,MOD)
    if q-1>=0:
        pow3q_1=pow(3,q-1,MOD)
    else:
        pow3q_1=0
    if q-2>=0:
        pow3q_2=pow(3,q-2,MOD)
    else:
        pow3q_2=0
    if q-3>=0:
        pow3q_3=pow(3,q-3,MOD)
    else:
        pow3q_3=0
    
    for x in l_B:
        ans+=A[x]*(C[len(S)]-C[x+1])*pow3q
        ans+=Q[x]*(C[len(S)]-C[x+1])*pow3q_1
        ans+=A[x]*(Q[len(S)]-Q[x+1])*pow3q_1
        ans+=Q[x]*(Q[len(S)]-Q[x+1])*pow3q_2
        ans%=MOD
    for x in l_Q:
        ans+=A[x]*(C[len(S)]-C[x+1])*pow3q_1
        ans+=Q[x]*(C[len(S)]-C[x+1])*pow3q_2
        ans+=A[x]*(Q[len(S)]-Q[x+1])*pow3q_2
        ans+=Q[x]*(Q[len(S)]-Q[x+1])*pow3q_3
        ans%=MOD        
    print(ans)
    

if __name__ == '__main__':
    main()

Buggy 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():
    S=list(input())
    A,C,Q=[0]*(len(S)+1),[0]*(len(S)+1),[0]*(len(S)+1)
    l_B=[]
    l_Q=[]
    q=0
    for i in range(len(S)):
        A[i+1]=A[i]+(S[i]=='A')
        C[i+1]=C[i]+(S[i]=='C')
        Q[i+1]=Q[i]+(S[i]=='?')
        if S[i]=='?':
            q+=1
            l_Q.append(i)
        if S[i]=='B':
            l_B.append(i)
    ans=0
    pow3q=pow(3,q,MOD)
    pow3q_1=pow(3,q-1,MOD)
    pow3q_2=pow(3,q-2,MOD)
    pow3q_3=pow(3,q-3,MOD)
    
    for x in l_B:
        ans+=A[x]*(C[len(S)]-C[x+1])*pow3q
        ans+=Q[x]*(C[len(S)]-C[x+1])*pow3q_1
        ans+=A[x]*(Q[len(S)]-Q[x+1])*pow3q_1
        ans+=Q[x]*(Q[len(S)]-Q[x+1])*pow3q_2
        ans%=MOD
    for x in l_Q:
        ans+=A[x]*(C[len(S)]-C[x+1])*pow3q_1
        ans+=Q[x]*(C[len(S)]-C[x+1])*pow3q_2
        ans+=A[x]*(Q[len(S)]-Q[x+1])*pow3q_2
        ans+=Q[x]*(Q[len(S)]-Q[x+1])*pow3q_3
        ans%=MOD        
    print(ans)
    

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

Fixed submission:
n = int(input())
items = set()
for _ in range(n):
  s = input()
  items.add(s)
print(len(items))

Buggy submission (verdict: Runtime Error):
n = int(input())
items = set()
for _ range(n):
  s = input()
  items.add(s)
print(len(items))
Problem p02729 (python)

Fixed submission:
a,b=map(int, input().split(' '))
 
ans = 0
if a>=2:
    ans += a*(a-1)//2
if b>=2:
    ans += b*(b-1)//2
print(ans)

Buggy submission (verdict: Runtime Error):
a,b=int(input().split(' '))

ans = 0
if a>=2:
    ans += a*(a-1)//2
if b>=2:
    ans += b*(b-1)//2
print(ans)
Problem p02951 (python)

Fixed submission:
a,b,c = list(map(int, input().split(' ')))
print(max(0, c-a+b))

Buggy submission (verdict: Runtime Error):
a,b,c = list(map(lambda int: input().split(' '))
print(c-a+b)
Problem p03209 (python)

Fixed submission:
ri = lambda: map(int, input().split(' '))
L = [1]
C = [1]

def rec(n, x):
	if x == 0:
		return 0

	if n == 0:
		return 1

	if x == L[n]:
		return 2*C[n-1] + 1

	ans = 0
	if x >= L[n-1] + 2:
		ans += C[n-1] + 1
		ans += rec(n-1, x-L[n-1]-2)
	else:
		ans += rec(n-1, x-1)

	return ans

if __name__ == '__main__':
	N, X = ri()
	for i in range(1, N+1):
		L.append(2*L[i-1] + 3)
		C.append(2*C[i-1] + 1)
	ans = rec(N, X)
	print(ans)

Buggy submission (verdict: Runtime Error):
ri = lambda: map(int, input().split(' '))
L = [1]
C = [1]

def rec(n, x):
	if x <= 1:
		return 0

	if x == L[n]:
		return 2*C[L-1] + 1

	ans = 0
	if x >= L[n-1] + 2:
		ans += C[n-1] + 1
		ans += rec(n-1, x-L[n-1]-2)
	else:
		ans += rec(n-1, x-1)

	return ans

if __name__ == '__main__':
	N, X = ri()
	for i in range(1, N+1):
		L.append(2*L[i-1] + 3)
		C.append(2*C[i-1] + 1)
	ans = rec(N, X)
	print(ans)
Problem p02862 (python)

Fixed submission:
import functools, sys

x, y = map(int, input().split())

mod = 10 ** 9 + 7

def modpow(x, y):
    z = 1
    while y > 0:
        if y % 2 == 0:
            x = (x * x) % mod
            y //= 2
        else:
            z = (z * x) % mod
            y -= 1
    return z

def modinv(x):
    return modpow(x, mod - 2)

def c(n, r):
    if n == r or r == 0:
        return 1

    fct = [None] * (n + 1)
    fct[0] = 1
    for i in range(1, n + 1):
        fct[i] = fct[i - 1] * i % mod
    return fct[n] * (modinv(fct[n - r]) * modinv(fct[r]) % mod) % mod

def f():
    if 2 * y - x < 0 or (2 * y - x) % 3 != 0:
        return 0
    a = (2 * y - x) // 3
    b = y - 2 * a
    if b < 0:
        return 0
    
    return c(a + b, a)

print(f())

Buggy submission (verdict: Runtime Error):
import functools, sys

x, y = map(int, input().split())

mod = 10 ** 9 + 7

def modpow(x, y):
    z = 1
    while y > 0:
        if y % 2 == 0:
            x = (x * x) % mod
            y //= 2
        else:
            z = (z * x) % mod
            y -= 1
    return z

def modinv(x):
    return modpow(x, mod - 2)

def c(n, r):
    if n == r or r == 0:
        return 1

    fct = [None] * (n + 1)
    fct[0] = 1
    for i in range(1, n + 1):
        fct[i] = fct[i - 1] * i % mod
    return fct[n] * (modinv(fct[n - r]) * modinv(fct[r]) % mod) % mod

def f():
    if (2 * y - x) % 3 != 0:
        return 0
    a = (2 * y - x) // 3
    b = y - 2 * a
    if b < 0:
        return 0
    
    return c(a + b, a)

print(f())
Problem p02863 (python)

Fixed submission:
import collections

n, t = map(int, input().split())
tpls = list(sorted(tuple(map(int, input().split())) for _ in range(n)))
a = [None] * n
b = [None] * n
for i in range(n):
    a[i], b[i] = tpls[i]

dp = [[0] * (t + 1) for _ in range(n + 1)]
for i in range(n):
    for j in range(t):
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
        k = min(t, j + a[i])
        dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + b[i])
print(max(map(max, dp)))

Buggy submission (verdict: Runtime Error):
import collections

n, t = map(int, input().split())
a = [None] * n
b = [None] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())

dp = [collections.defaultdict(int) for _ in range(n + 1)]
dp[0][0] = 0
for i in sorted(range(n), key=lambda x: a[x]):
    for cur in dp[i]:
        dp[i + 1][cur] = max(dp[i + 1][cur], dp[i][cur])
        if cur < t:
            dp[i + 1][cur + a[i]] = max(dp[i + 1][cur + a[i]], dp[i][cur] + b[i])
print(max(dp[n].values()))
Problem p03108 (python)

Fixed submission:
class UnionFind(object):
    def __init__(self, size):
        self.size = size
        self.parents = list(range(size))
        self.counts = [1] * size

    def find(self, x):
        history = []
        while self.parents[x] != x:
            history.append(x)
            x = self.parents[x]
        
        for i in history: 
            self.parents[i] = x
        return x
    
    def union(self, x1, x2):
        y1 = self.find(x1)
        y2 = self.find(x2)
        if y1 != y2:
            self.parents[y2] = y1
            self.counts[y1] += self.counts[y2]

    def count(self, x):
        return self.counts[self.find(x)]
    
if __name__ == '__main__':
    n, m = map(int, input().split())
    alist = []
    blist = []
    for _ in range(m):
        a, b = map(int, input().split())
        alist.append(a - 1)
        blist.append(b - 1)

    answers = [n * (n - 1) // 2]
    uf = UnionFind(n)

    for a, b in zip(reversed(alist), reversed(blist)):
        answers.append(answers[-1])
        c = uf.find(a)
        d = uf.find(b)
        if c == d: 
            continue
  
        answers[-1] -= uf.count(a) * uf.count(b)
        uf.union(a, b)

    for i in reversed(range(m)):
        print(answers[i])

Buggy submission (verdict: Runtime Error):
class UnionFind(object):
    def __init__(self, size):
        self.size = size
        self.parents = list(range(size))
        self.counts = [1] * size

    def find(self, x):
        parent = self.parents[x]
        if x == parent:
            return x
        else:
            self.parents[x] = self.find(parent)
            return self.parents[x]
    
    def union(self, x1, x2):
        y1 = self.find(x1)
        y2 = self.find(x2)
        if y1 != y2:
            self.parents[y2] = y1
            self.counts[y1] += self.counts[y2]

    def count(self, x):
        return self.counts[self.find(x)]
    
if __name__ == '__main__':
    n, m = map(int, input().split())
    alist = []
    blist = []
    for _ in range(m):
        a, b = map(int, input().split())
        alist.append(a - 1)
        blist.append(b - 1)

    answers = [n * (n - 1) // 2]
    uf = UnionFind(n)

    for a, b in zip(reversed(alist), reversed(blist)):
        answers.append(answers[-1])
        
        c = uf.find(a)
        d = uf.find(b)
        if c == d: 
            continue
  
        answers[-1] -= uf.count(a) * uf.count(b)
        uf.union(a, b)

    for i in reversed(range(m)):
        print(answers[i])
Problem p03834 (python)

Fixed submission:
s = input()
t = s.replace(',', ' ')
print(t)

Buggy submission (verdict: Runtime Error):
sx, sy, tx, ty = map(int, input().split())
dx, dy = tx - sx, ty - sy

ans = "" 
ans += 'U' * dy + 'R' * dx 
ans += 'D' * dy + 'L' * dx
ans += 'L'
ans += 'U' * (dy + 1) + 'R' * (dx + 1)
ans += 'D'
ans += 'R'
ans += 'D' * (dy + 1) + 'L' * (dx + 1)
ans += 'U'

print(ans)