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

Fixed submission:
N, X = map(int, input().split())
a = [1] * (N+1)
p = [1] * (N+1)
for i in range(1,N+1):
    a[i] = a[i-1]*2 + 3
    p[i] = p[i-1]*2 + 1
def f(n, x):
    if n == 0:
        return 1
    elif x == 1:
        return 0
    elif 2<= x <= a[n-1] + 1:
        return f(n-1, x-1)
    elif x == a[n-1] + 2:
        return p[n-1] + 1
    elif a[n-1]+3 <= x <= 2*a[n-1]+2:
        return p[n-1]+1+ f(n-1, x-(a[n-1]+2))
    elif x == 2*a[n-1]+3:
        return p[n]
print(f(N,X))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1000000)
def burger(l):
    memo = [0] * (l+1)
    def l_burger(l):
        if l == 0:
            return 'P'
        if memo[l] != 0:
            return memo[l]
        
        memo[l] = 'B' + l_burger(l-1) + 'P' + l_burger(l-1) + 'B'
        return memo[l]
    return l_burger(l)
n, x = map(int, input().split())
cnt = 0
for i in burger(n)[:x]:
    if i == 'P':
        cnt += 1
        
print(cnt)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10000000000)
def burger(l):
    memo = [0] * (l+1)
    def l_burger(l):
        if l == 0:
            return 'P'
        if memo[l] != 0:
            return memo[l]
        
        memo[l] = 'B' + l_burger(l-1) + 'P' + l_burger(l-1) + 'B'
        return memo[l]
    return l_burger(l)
n, x = map(int, input().split())
cnt = 0
for i in burger(n)[:x]:
    if i == 'P':
        cnt += 1
        
print(cnt)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(100000000000000000)
def burger(l):
    memo = [0] * (l+1)
    def l_burger(l):
        if l == 0:
            return 'P'
        if memo[l] != 0:
            return memo[l]
        
        memo[l] = 'B' + l_burger(l-1) + 'P' + l_burger(l-1) + 'B'
        return memo[l]
    return l_burger(l)
n, x = map(int, input().split())
cnt = 0
for i in burger(n)[:x]:
    if i == 'P':
        cnt += 1
        
print(cnt)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(100000)
def burger(l):
    memo = [0] * (l+1)
    def l_burger(l):
        if l == 0:
            return 'P'
        if memo[l] != 0:
            return memo[l]
        
        memo[l] = 'B' + l_burger(l-1) + 'P' + l_burger(l-1) + 'B'
        return memo[l]
    return l_burger(l)
n, x = map(int, input().split())
cnt = 0
for i in burger(n)[:x]:
    if i == 'P':
        cnt += 1
        
print(cnt)
Problem p03634 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
n=int(input())
G=[[]for i in range(n+1)]
for i in range(n-1):
    a, b, c = map(int,input().split())
    G[a] += (b,c),
    G[b] += (a,c),
q, k = map(int,input().split())
d = [0]*(n+1) #kから各点への距離
def f(v,p,u): #v:今見ているとこ p:一つ前に見たとこ u:kからの距離
    d[v] = u
    for t, c in G[v]:
        if p != t:
            f(t,v,u+c)
f(k,0,0)
for i in range(q):
    x, y = map(int,input().split())
    print(d[x]+d[y])

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**5)
n=int(input())
G=[[]for i in range(n+1)]
for i in range(n-1):
    a, b, c = map(int,input().split())
    G[a] += (b,c),
    G[b] += (a,c),
q, k = map(int,input().split())
d = [0]*(n+1) #kから各点への距離
def f(v,p,u): #v:今見ているとこ p:一つ前に見たとこ u:kからの距離
    d[v] = u
    for t, c in G[v]:
        if p != t:
            f(t,v,u+c)
f(k,0,0)
for i in range(q):
    x, y = map(int,input().split())
    print(d[x]+d[y])

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)
n=int(input())
G=[[]for i in range(n+1)]
for i in range(n-1):
    a, b, c = map(int,input().split())
    G[a] += (b,c)
    G[b] += (a,c)
q, k = map(int,input().split())
d = [0]*(n+1) #kから各点への距離
def f(v,p,u): #v:今見ているとこ p:一つ前に見たとこ u:kからの距離
    d[v] = u
    for t, c in G[v]:
        if p != t:
            f(t,v,u+c)
f(k,0,0)
for i in range(q):
    x, y = map(int,input().split())
    print(d[x]+d[y])
Problem p03804 (python)

Fixed submission:
N , M = map(int, input().split())
As =[input() for _ in range(N)]
Bs =[input() for _ in range(M)]
m = N-M
for i in range(m+1):
    for j in range(m+1):
        flag = True
        for k in range(M):
            for l in range(M):
                if As[k+i][l+j] != Bs[k][l]:
                    flag = False
                    break
            if not flag:
                break
        if flag:
            break
    if flag:
        break
if flag:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
N , M = map(int, input().split())
As =[input() for _ in range(N)]
Bs =[input() for _ in range(M)]
m = N-M
for i in range(m):
    for j in range(m):
        flag = True
        for k in range(M):
            for l in range(M):
                if As[k+i][l+j] != Bs[k][l]:
                    flag = False
                    break
            if not flag:
                break
        if flag:
            break
    if flag:
        break
if flag:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
N , M = map(int, input().split())
As =[input() for _ in range(N)]
Bs =[input() for _ in range(M)]
m = N-M
for i in range(m):
    for j in range(m):
        flag = True
        for k in range(i, M+i):
            for l in range(j, M+j):
                if As[k][l] != Bs[k-i][l-j]:
                    flag = False
                    break
            if not flag:
                break
        if flag:
            break
    if flag:
        break
if flag:
    print('Yes')
else:
    print('No')
Problem p03201 (python)

Fixed submission:
from collections import defaultdict
N=int(input())
A=[int(i) for i in input().split()]
dd=defaultdict(int)
for a in A:
    dd[a]+=1
#print(dd)
B=sorted(A,reverse=True)
ans=0
for x in B:
    #print(x)
    if dd.get(x,-1)==0:
        continue
    s=len(bin(x))-3
    if x==1<<s:
        t=dd.get(x,-1)
        if t!=-1:
            ans+=t//2
            dd[x]-=(t//2)*2
            #print(ans)
            #print(dd)
    else:
        s+=1
        #print((1<<s)-x)
        t=dd.get((1<<s)-x,-1)
        if t>=1:
            ans+=1
            dd[x]-=1
            dd[(1<<s)-x]-=1
            #print(ans)
            #print(dd)
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
def debug(*args): print(*args, file=sys.stderr)
N=int(input())
A=[int(i) for i in input().split()]
dd=defaultdict(int)
for a in A:
    dd[a]+=1
#print(dd)
B=sorted(A,reverse=True)
ans=0
for x in B:
    debug(*args)
    #print(x)
    if dd.get(x,-1)==0:
        continue
    s=len(bin(x))-3
    if x==1<<s:
        t=dd.get(x,-1)
        if t!=-1:
            ans+=t//2
            dd[x]-=(t//2)*2
            #print(ans)
            #print(dd)
    else:
        s+=1
        #print((1<<s)-x)
        t=dd.get((1<<s)-x,-1)
        if t>=1:
            ans+=1
            dd[x]-=1
            dd[(1<<s)-x]-=1
            #print(ans)
            #print(dd)
print(ans)
Problem p03329 (python)

Fixed submission:
N = int(input())
A=[]
A.append(1)
for i in range(1,7):
    A.append(6**i)
for i in range(1,6):
    A.append(9**i)
A.sort()
dp=[10*5+5]*(N+1)
dp[0]=0
for i in range(1,N+1):
    for s in range(len(A)):
        if i-A[s]>=0:
            dp[i]=min(dp[i-A[s]]+1,dp[i])
print(dp[N])

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
N,C = map(int,input().split())
D=[[int(i) for i in input().split()] for j in range(C)]
co=[[int(i) for i in input().split()] for j in range(N)]
d0= defaultdict(int)
d1= defaultdict(int)
d2= defaultdict(int)
for i in range(N):
    for j in range(N):
        if (j+i) %3==0:
            d0[co[j][i]] +=1
        elif (j+i)%3==1:
            d1[co[j][i]] +=1
        else:
            d2[co[j][i]] +=1
A0=[]#i色に帰るのに必要な違和感
A1=[]
A2=[]
for i in range(C):
    iwa =0
    for s in d0.keys():
        iwa += D[s-1][i-1]*d0[s] 
    A0.append([iwa,i])
for i in range(C):
    iwa =0
    for s in d1.keys():
        iwa += D[s-1][i-1]*d1[s] 
    A1.append([iwa,i])
for i in range(C):
    iwa =0
    for s in d2.keys():
        iwa += D[s-1][i-1]*d2[s] 
    A2.append([iwa,i])

A0.sort()
A1.sort()
A2.sort()
B=[[] for i in range(3)]
for i in range(3):
    B[0].append(A0[i])
for i in range(3):
    B[1].append(A1[i])
for i in range(3):
    B[2].append(A2[i])
ans =[]
for i in range(3):
    for j in range(3):
        for k in range(3):
            if B[0][i][1] ==B[1][j][1]:
                continue
            if B[0][i][1] ==B[2][k][1]:
                continue
            if B[1][j][1] ==B[2][k][1]:
                continue
            ans.append(B[0][i][0]+B[1][j][0]+B[2][k][0])
print(min(ans))
Problem p03332 (python)

Fixed submission:
N,A,B,K=map(int,input().split())
mod = 998244353
#x!のmodP逆元を求めるx^-1=x^(p-2)
table=[1]
a=1
for i in range(1,N+1):
    a=(a*pow(i,mod-2,mod))%mod
    table.append(a)

num=1
for i in range(1,N+1):
    num = (num*i) %mod


number =0
for i in range(N+1):
    if (K-A*i)%B==0 and K-A*i>=0:
        j=(K-A*i)//B
        if 0<=j<=N:
            t = (num*num)%mod
            t = (t*table[i])%mod
            t = (t*table[j])%mod
            t = (t*table[N-i])%mod
            t = (t*table[N-j])%mod
            number = (number+t)%mod
print(number)

Buggy submission (verdict: Runtime Error):
N,A,B,K=map(int,input().split())
mod = 998244353
#x!のmodP逆元を求めるx^-1=x^(p-2)
table=[1]
a=1
for i in range(1,N+1):
    a=(a*pow(i,mod-2,mod))%mod
    table.append(a)

num=1
for i in range(1,N+1):
    num = (num*i) %mod


number =0
for i in range(N):
    if (K-A*i)%B==0 and K-A*i>=0:
        j=(K-A*i)//B
        t = (num*num)%mod
        t = (t*table[i])%mod
        t = (t*table[j])%mod
        t = (t*table[N-i])%mod
        t = (t*table[N-j])%mod
        number = (number+t)%mod
print(number)

Buggy submission (verdict: Runtime Error):
from fractions import gcd
import sys
sys.setrecursionlimit(10**7) 

N,A,B,K=map(int,input().split())
mod = 998244353
#x!のmodP逆元を求めるx^-1=x^(p-2)
table=[1]
a=1
for i in range(1,N+1):
    a=(a*pow(i,mod-2,mod))%mod
    table.append(a)

num=1
for i in range(1,N+1):
    num = (num*i) %mod


number =0
for i in range(N):
    if (K-A*i)%B==0 and K-A*i>=0:
        j=(K-A*i)//B
        t = (num*num)%mod
        t = (t*table[i])%mod
        t = (t*table[j])%mod
        t = (t*table[N-i])%mod
        t = (t*table[N-j])%mod
        number = (number+t)%mod
print(number)

Buggy submission (verdict: Runtime Error):
from fractions import gcd
import sys
sys.setrecursionlimit(10**7) 

N,A,B,K=map(int,input().split())
mod = 998244353
#x!のmodP逆元を求めるx^-1=x^(p-2)
table=[1]
a=1
for i in range(1,N+1):
    a=(a*pow(i,mod-2,mod))%mod
    table.append(a)

num=1
for i in range(1,N+1):
    num = (num*i) %mod


number =0
for i in range(N):
    if (K-A*i)%B==0:
        j=(K-A*i)//B
        t = (num*num)%mod
        t = (t*table[i])%mod
        t = (t*table[j])%mod
        t = (t*table[N-i])%mod
        t = (t*table[N-j])%mod
        number = (number+t)%mod
print(number)

Buggy submission (verdict: Runtime Error):
from fractions import gcd
import sys
sys.setrecursionlimit(10**7) 

N,A,B,K=map(int,input().split())
mod = 998244353
#x!のmodP逆元を求めるx^-1=x^(p-2)
table=[1]
a=1
for i in range(1,N+1):
    a=(a*pow(i,mod-2,mod))%mod
    table.append(a)

num=1
for i in range(1,N+1):
    num = (num*i) %mod


number =0
for i in range(N):
    if (K-A*i)%B==0:
        j=(K-A*i)//B
        t = (num*num)%mod
        t = (t*table[i])%mod
        t = (t*table[j])%mod
        t = (t*table[N-i])%mod
        t = (t*table[N-j])%mod
        number = (number+t)%mod
print(number)
Problem p03768 (python)

Fixed submission:
import sys
input = sys.stdin.readline
from collections import deque
N,M=map(int,input().split())
table=[[] for i in range(N)]
for i in range(M):
    a,b=map(int,input().split())
    a,b=a-1,b-1
    table[a].append(b)
    table[b].append(a)
Q=int(input())
X=[[int(i) for i in input().split()] for i in range(Q)]
color=[0]*Q
dp=[[-1]*N for i in range(11)]
for i in range(Q-1,-1,-1):
    v, d, c=X[i]
    v=v-1
    color[i]=c
    dp[d][v]=max(dp[d][v],i)

for d in range(10,0,-1):
    for x in range(N):
        for y in table[x]:
            dp[d-1][y]=max(dp[d][x],dp[d-1][y])
for i in range(N):
    s=-1
    for d in range(11):
        s=max(s,dp[d][i])
    if s==-1:
        print(0)
    else:
        print(color[s])

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
from collections import deque
N,M=map(int,input().split())
table=[[] for i in range(N)]
for i in range(M):
    a,b=map(int,input().split())
    a,b=a-1,b-1
    table[a].append(b)
    table[b].append(a)
Q=int(input())
X=[[int(i) for i in input().split()] for i in range(Q)]
color=[0]*Q
dp=[[-1]*N for i in range(10)]
for i in range(Q-1,-1,-1):
    v, d, c=X[i]
    v=v-1
    color[i]=c
    dp[d][v]=i

for d in range(9,0,-1):
    for x in range(N):
        for y in table[x]:
            dp[d-1][y]=max(dp[d][x],dp[d-1][y])
for i in range(N):
    s=-1
    for d in range(10):
        s=max(s,dp[d][i])
    if s==-1:
        print(0)
    else:
        print(color[s])
Problem p03221 (python)

Fixed submission:
N, M = [int(i) for i in input().split(" ")]
p = list()
y = list()
yd = {}
for i in range(0, M):
    pi, yi = [int(i) for i in input().split(" ")]
    p.append(pi)
    y.append(yi)
    if pi in yd.keys():
        yd[pi].append(yi)
    else:
        yd[pi] = [yi]

ydid = {}
for i in yd.keys():
    num = 1
    for j in sorted(yd[i]):
        ydid[j] = num
        num = num + 1

for i in range(0, M):
    print("{:06}{:06}".format(p[i], ydid[y[i]]))

Buggy submission (verdict: Runtime Error):
N, M = [int(i) for i in input().split(" ")]
p = list()
y = list()
yd = {}
for i in range(0, M):
    pi, yi = [int(i) for i in input().split(" ")]
    p.append(pi)
    y.append(yi)
    if pi in yd.keys():
        yd[pi].append(yi)
    else:
        yd[pi] = [yi]

ydid = {}
for i in yd.keys():
    num = 1
    for j in sorted(yd[p[i]]):
        ydid[j] = num
        num = num + 1

for i in range(0, M):
    print("{:06}{:06}".format(p[i], ydid[y[i]]))
Problem p02989 (python)

Fixed submission:
N=int(int(input())/2)
a=sorted(list(map(int,input().split())))
print(int(a[N])-int(a[N-1]))

Buggy submission (verdict: Runtime Error):
N=int(int(input())/2)
N-=(N+1)%2
a=sorted(input().split())
print(int(a[N+1])-int(a[N]))

Buggy submission (verdict: Runtime Error):
N=int(int(input())/2)
a=sorted(input().split())
print(int(a[N+1])-int(a[N]))

Buggy submission (verdict: Runtime Error):
N = int(input()) / 2
a = input().split()

if a[N] == a[N + 1]:
    print(0)
else:
    print(int(a[N+1]) - int(a[N]))

Buggy submission (verdict: Runtime Error):
N = int(input()) / 2
a = input().split()

if a[N] == a[N + 1]:
    print(0)
else:
    print(a[N+1] - a[N])
Problem p02990 (python)

Fixed submission:
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n, k = list(map(int, input().split()))

for i in range(1,k+1):
    if n - k + 1 >= i:
        ans = comb(n - k + 1, i) * math.factorial(k - 1) // math.factorial(k-i) // math.factorial(i-1)
        print(ans % 1000000007)
    else:
        print(0)

Buggy submission (verdict: Runtime Error):
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n, k = list(map(int, input().split()))

if n == k:
    print(1)
    for _ in range(k-1):
        print(0)
    
    exit()

for i in range(1,k+1):
    ans = comb(n - k + 1, i) * math.factorial(k - 1) // math.factorial(k-i) // math.factorial(i-1)
    print(ans % 1000000007)

Buggy submission (verdict: Runtime Error):
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n, k = list(map(int, input().split()))

for i in range(1,k+1):
    ans = comb(n - k + 1, i) * math.factorial(k - 1) // math.factorial(k-i) // math.factorial(i-1)
    print(ans % 1000000007)
Problem p03013 (python)

Fixed submission:
n, m = map(int, input().split())
dp = [0] * (n + 1)
a = []
for i in range(m):
    aa = int(input())
    dp[aa] = -1
    a.append(aa)
for i in range(m - 1):
    if a[i] + 1 == a[i + 1]:
        print(0)
        exit()
mod = 10 ** 9 + 7

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

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
dp = [-1] * (n + 1)
a = []
for i in range(m):
    aa = int(input())
    a.append(aa)
    dp[aa - 1] = 0
mod = 10 ** 9 + 7

dp[0] = 1
if a[0] != 1:
    dp[1] = 1
for i in range(1, n):
    if dp[i + 1] == -1:
        dp[i + 1] = (dp[i] + dp[i - 1]) % mod
print(dp[n])

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(200000)
input = sys.stdin.readline

n, m = map(int, input().split())
dp = [-1] * (n + 1)
a = []
for i in range(m):
    aa = int(input())
    a.append(aa)
    dp[aa - 1] = 0
mod = 10 ** 9 + 7

dp[0] = 1
if a[0] != 1:
    dp[1] = 1
for i in range(1, n):
    if dp[i + 1] == -1:
        dp[i + 1] = (dp[i] + dp[i - 1]) % mod
print(dp[n])

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(200000)
input = sys.stdin.readline

n, m = map(int, input().split())
dp = [-1] * (n + 1)
a = []
for i in range(m):
    aa = int(input())
    a.append(aa)
    dp[aa] = 0
mod = 10 ** 9 + 7

dp[0] = 1
if a[0] != 1:
    dp[1] = 1
for i in range(1, n):
    if dp[i + 1] == -1:
        dp[i + 1] = (dp[i] + dp[i - 1]) % mod
print(dp[n])

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
dp = [-1] * (n + 1)
a = []
for i in range(m):
    aa = int(input())
    a.append(aa)
    dp[aa] = 0
mod = 10 ** 9 + 7

dp[0] = 1
if a[0] != 1:
    dp[1] = 1
for i in range(1, n):
    if dp[i + 1] == -1:
        dp[i + 1] = (dp[i] + dp[i - 1]) % mod
print(dp[n])

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
dp = [-1] * (n + 1)
a = []
for i in range(m):
    aa = int(input())
    a.append(aa)
    dp[aa] = 0
mod = 10 ** 9 + 7

dp[0] = 1
if a[0] != 1:
    dp[1] = 1
for i in range(1, n):
    if dp[i + 1] == -1:
        dp[i + 1] = (dp[i] + dp[i - 1]) % mod
print(dp[n])

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
dp = [-1] * (n + 1)
a = []
for i in range(m):
    aa = int(input())
    if a:
        if a[-1] == aa - 1:
            print(0)
            exit()
    a.append(aa)
    dp[aa] = 0
mod = 10 ** 9 + 7

dp[0] = 1
if a[0] != 1:
    dp[1] = 1
for i in range(1, n):
    if dp[i + 1] == -1:
        dp[i + 1] = (dp[i] + dp[i - 1]) % mod
print(dp[n])
Problem p03053 (python)

Fixed submission:
from collections import deque

h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
cnt = [[-1] * w for _ in range(h)]

def bfs():
    queue = deque()
    for i in range(h):
        for j in range(w):
            if s[i][j] == "#":
                queue.append([i, j])
                cnt[i][j] = 0
    while queue:
        i, j = queue.popleft()
        for di, dj in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            if 0 <= i + di < h and 0 <= j + dj < w and cnt[i + di][j + dj] == -1:
                queue.append([i + di, j + dj])
                cnt[i + di][j + dj] = cnt[i][j] + 1

bfs()
print(max([max(l) for l in cnt]))

Buggy submission (verdict: Runtime Error):
from collections import deque

h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]

def bfs(y, x):
    cnt = [[-1] * w for _ in range(h)]
    queue = deque([[y, x]])
    cnt[y][x] = 1
    while queue:
        i, j = queue.popleft()
        for di, dj in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            if 0 <= i + di < h and 0 <= j + dj < w and cnt[i + di][j + dj] == -1:
                if s[i + di][j + dj] == ".":
                    cnt[i + di][j + dj] = cnt[i][j] + 1
                    queue.append([i + di, j + dj])
                else:
                    return cnt[i][j]

ans = 0
i = 0
j = 0
while i < h:
    while j < w:
        if s[i][j] == ".":
            ans = max(ans, bfs(i, j))
            i += ans
            j += ans
print(ans)
Problem p03253 (python)

Fixed submission:
import collections
n, m = map(int, input().split())

factor = []
tmp = int(m ** (1/2)) + 1
for i in range(2, tmp):
    while m % i == 0:
        m //= i
        factor.append(i)
if m > 1:
    factor.append(m)
num = list(collections.Counter(factor).most_common())

def comb(n, r):
    tmp = 1
    for i in range(r):
        tmp *= n - i
    for i in range(r):
        tmp //= r - i
    return tmp

ans = 1
for x in num:
    ans *= (comb(x[1] + n - 1, x[1]) % 1000000007)
    ans %= 1000000007
print(ans)

Buggy submission (verdict: Runtime Error):
import math
import collections
n, m = map(int, input().split())

factor = []
tmp = int(m ** (1/2)) + 1
for i in range(2, tmp):
    while m % i == 0:
        m //= i
        factor.append(i)
if m > 1:
    factor.append(m)
num = list(collections.Counter(factor).most_common())

ans = 1
for i in range(len(num)):
    ans *= (math.factorial(num[i] + n - 1) // (math.factorial(n - 1) * math.factorial(num[i])) % 1000000007)
    ans %= 1000000007
print(ans)
Problem p03634 (python)

Fixed submission:
import sys
sys.setrecursionlimit(200000)

n = int(input())
edge = [[[] for i in range(2)] for j in range(n)]
dp = [-1] * n
for i in range(n - 1):
    a, b, c = map(int, input().split())
    edge[a - 1][0].append(b - 1)
    edge[a - 1][1].append(c)
    edge[b - 1][0].append(a - 1)
    edge[b - 1][1].append(c)


def distance(x, prev, d):
    dp[x] = d
    for i, j in zip(edge[x][0], edge[x][1]):
        if i == prev:
            continue
        if dp[i] != -1:
            continue
        distance(i, x, d + j)
    return

q, k = map(int, input().split())
k -= 1

ans = []
distance(k, -1, 0)
for i in range(q):
    x, y = map(int, input().split())
    ans.append(dp[x - 1] + dp[y - 1])

for i in range(q):
    print(ans[i])

Buggy submission (verdict: Runtime Error):
n = int(input())
edge = [[[] for i in range(2)] for j in range(n)]
dp = [-1] * n
for i in range(n - 1):
    a, b, c = map(int, input().split())
    edge[a - 1][0].append(b - 1)
    edge[a - 1][1].append(c)
    edge[b - 1][0].append(a - 1)
    edge[b - 1][1].append(c)


def distance(x, prev, d):
    dp[x] = d
    for i, j in zip(edge[x][0], edge[x][1]):
        if i == prev:
            continue
        if dp[i] != -1:
            continue
        distance(i, x, d + j)
    return

q, k = map(int, input().split())
k -= 1

ans = []
distance(k, -1, 0)
for i in range(q):
    x, y = map(int, input().split())
    ans.append(dp[x - 1] + dp[y - 1])

for i in range(q):
    print(ans[i])
Problem p03012 (python)

Fixed submission:
N = int(input())
W = [int(i) for i in input().split()] 
onon = 0
hoge = sum(W)
nowresult = sum(W)
for i in range(N):
    onon += W[i]
    hoge -= W[i]
    result = abs(onon - hoge)
    if result <= nowresult:
        nowresult = result
print(nowresult)

Buggy submission (verdict: Runtime Error):
N = int(input())
W = [int(i) for i in input().split()] 
onon = 0
hoge = sum(W)
for i in range(N):
    onon += W[0]:
    hoge -= W[0]:
    result = abs(onon - hoge)
    if result <= nowresult:
        nowresult = result
print(nowresult)