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

Fixed submission:
# 入力                                                                                   
S = input()
K = int(input())

# kindリストに同じ文字が続くものごとに区切ったものを格納                                 
kind = []
back = "0"
len_S = len(S)
i = 0
for moji in S:
    if i == 0:
        back = moji
        i += 1
        continue
    if moji == back[-1]:
        back = moji + back
        if i == len_S-1:
            kind.append(back)
    else:
        kind.append(back)
        back = moji
    i += 1

score = 0
# 文字列が1文字の時
if len(S) == 1:
  	print(K//2)
   
# 最初の文字と最後の文字が異なる時                                                       
elif S[0] != S[-1]:
    for word in kind:
        len_word = len(word)
        score += len_word // 2
    print(score*K)
# 最初の文字と最後の文字が一緒の時                                                       
else:
    if len(set(kind)) == 1:
      	if len(kind) == 1:
          	print(len(kind[0])*K//2)
      	else:
        	print((len(kind[0])//2)*K)
    else:
        # 最初と最後がつながることでできる文字列の長さ                                   
        len_sg = len(kind[0] + kind[-1])
        for word in kind[1:-1]:
            len_word = len(word)
            score += len_word // 2
        print(score*K + (len_sg//2)*(K-1) + (len(kind[0]))//2 + (len(kind[-1]))//2 )

Buggy submission (verdict: Runtime Error):
# 入力                                                                                   
S = input()
K = int(input())

# kindリストに同じ文字が続くものごとに区切ったものを格納                                 
kind = []
back = "0"
len_S = len(S)
i = 0
for moji in S:
    if i == 0:
        back = moji
        i += 1
        continue
    if moji == back[-1]:
        back = moji + back
        if i == len_S-1:
            kind.append(back)
    else:
        kind.append(back)
        back = moji
    i += 1

score = 0
# 最初の文字と最後の文字が異なる時                                                       
if S[0] != S[-1]:
    for word in kind:
        len_word = len(word)
        score += len_word // 2
    print(score*K)
# 最初の文字と最後の文字が一緒の時                                                       
else:
    if len(set(kind)) == 1:
        print((len(kind[0])//2)*K)
    else:
        # 最初と最後がつながることでできる文字列の長さ                                   
        len_sg = len(kind[0] + kind[-1])
        for word in kind[1:-1]:
            len_word = len(word)
            score += len_word // 2
        print(score*K + (len_sg//2)*(K-1) + (len(kind[0]))//2 + (len(kind[-1]))//2 )
Problem p02948 (python)

Fixed submission:
from heapq import *
n,m = map(int,input().split())
l = [[] for i in range(m+1)]
for i in range(n):
  a,b = map(int,input().split())
  if a < m+1:
    l[a].append(b)

ans = 0
a = []
for i in range(1,m+1):
  for j in l[i]:
    heappush(a,-j)
  if a:
    ans -= heappop(a)
print(ans)

Buggy submission (verdict: Runtime Error):
import heapq
n,m = map(int,input().split())
l = [0]*n
for i in range(n):
  l[i] = list(map(int,input().split()))
l.sort()

L = [[] for i in range(m+1)]
for i in range(n):
  if l[i][0] <= m:
    L[l[i][0]].append(l[i][1])

a = []
ans = 0
for i in range(m):
  key = i+1
  for j in L[key]:
    heapq.heappush(a, -L[i][j])
  if a != []:
    heapq.heapify(a)
    ans += heapq.heappop(a)
print(-ans)
Problem p03013 (python)

Fixed submission:
n,m = map(int,input().split())
a = [int(input()) for i in range(m)]
b = []
if a:
  b = [a[0]-1] + [a[i+1]-a[i]-2 for i in range(m-1)] + [n-a[m-1]-1]
c = [1,1]+[0]*(n-1)
for i in range(2,n+1):
  c[i] = c[i-1] + c[i-2]
ans = 1
if b:
  for j in b:
    if j == -1:
      ans = 0
      break
    ans = (ans * c[j]) %1000000007
else:
  ans = c[n] % 1000000007
print(ans)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
a = [int(input()) for i in range(m)]
b = [a[0]-1] + [a[i+1]-a[i]-2 for i in range(m-1)] + [n-a[m-1]-1]
c = [1,1]+[0]*(n-1)
for i in range(2,n+1):
  c[i] = c[i-1] + c[i-2]
ans = 1
for j in b:
  if j == -1:
    ans = 0
    break
  ans = ans * c[j] %1000000007
print(ans)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
h = []
for i in range(0,m):
  h.append(int(input()))
now = 0
s = 1
def c(i):
  if 0 <= i <= 2:
    return i
  else:
    return c(i-2) + c(i-1)

def check(h):
  if m == 1:
    return 0
  if m == 2 and h[0]+1 == h[1]:
    return -1
  for i in range(0,m-2):
    if h[i] + 1 == h[i+1]:
      return -1
  return 0

if check(h) == 0:
  for i in h:
    b = i - now - 1
    if b > 0:
      s = (s * c(b)) % 1000000007
    now = i + 1
  s = (s * c(n-now)) % 1000000007
  print(s)
else:
  print(0)
Problem p02847 (python)

Fixed submission:
day = {'SUN':7,'MON':6,'TUE':5,'WED':4,'THU':3,'FRI':2,'SAT':1}
s = input()
print(day[s])

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)
N = int(input())
v = [[] for i in range(N)]
for i in range(N-1):
    a,b = map(int,input().split())
    a,b = a-1,b-1
    v[a].append([b,i])

ans = [None] * (N-1)

def decide_colord(cur,color):
    cnt = 1
    for (to,j)in v[cur]:
        if cnt == color:
            cnt += 1
        ans[j] = cnt
        decide_colord(to,cnt)
        cnt += 1
decide_colord(0,0)
print(max(ans))
[print(a) for a in ans]
Problem p02859 (python)

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

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

N = int(input())
a = []
x = []
y = []
count = 0

def factorial(n):
    if n<2:
        return 1
    else:
        return(n*factorial(n-1))

for i in range(N):
    a.append(list(map(int,input().split())))    
for i in range(N):
    for j in range(N):
        if i==j:
            continue
        count += np.sqrt((a[i][0] - a[j][0])**2 + (a[i][1] - a[j][1])**2)
b = factorial(N)
#print(count/b)
print(count/N)

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

N = int(input())
a = []
x = []
y = []
count = 0

def factorial(n):
    if n<2:
        return 1
    else:
        return(n*factorial(n-1))

for i in range(N):
    a.append(list(map(int,input().split())))    
for i in range(N):
    for j in range(N):
        if i==j:
            continue
        count += np.sqrt((a[i][0] - a[j][0])**2 + (a[i][1] - a[j][1])**2)
b = factorial(N)
print(count/b)
#print(count/N)
Problem p02881 (python)

Fixed submission:
N = int(input())
x = N
y = N
ansx = N
ansy = N
ans = []
n = int(N**0.5)
if N**0.5 == int(N**0.5):
    print(int(N**0.5)*2-2)
else:
    for i in range(n+1):
        if N%(i+1) == 0:
            ans.append(i+1)
    ans.append(N)
    if(ans[1]==N):
        print(N-1)
    else:
        for i in range(len(ans)):
            if ansx+ansy>ans[i] + int(N//ans[i]):
                ansx = ans[i]
                ansy =int(N//ans[i])
        print(ansx + ansy -2)

Buggy submission (verdict: Runtime Error):
 N = int(input())
x = N
y = N
ansx = N
ansy = N
n = int(N**0.5)
for i in range(x+1):
    if i+1 > n:
        break
    for j in range(y+1):
        if j+1 > x+1:
            break
        if i*j == N:
            if ansx + ansy >i+j:
                ansx,ansy = i,j

print(ansx + ansy -2)
Problem p03013 (python)

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

for i in a:
    b[i]=-1

for i in range(2,n+1):
    if b[i]==-1:
        continue
    if b[i-1]!=-1:
        b[i]+=b[i-1]
    if b[i-2]!=-1:
        b[i]+=b[i-2]
        
print(b[-1]%mod)

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

for i in range(2,n+1):
    if b[i] == -1:
        continue
    if b[i-1] != -1:
        b[i] += b[i-1]
    if b[i-2] != -1:
        b[i] += b[i-2]

print(b[-1]%mod)

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

for i in range(2,n+1):
    if b[i] == -1:
        continue
    if b[i-1] != -1:
        b[i] += b[i-1]
    if b[i-2] != -1:
        b[i] += b[i-2]

print(b[-1]%mod)

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

for i in range(2,n+1):
    if b[i] == -1:
        continue
    if b[i-1] != -1:
        b[i] += b[i-1]
    if b[i-2] != -1:
        b[i] += b[i-2]

print(b[-1]%mod)
Problem p02984 (python)

Fixed submission:
import numpy as np

n = int(input())
a = [int(i) for i in input().split()] 
a = np.array(a)
x = np.zeros(n)

x[0] = sum(a) - (2*(sum(a[1::2])))

for i in range(n-1):
    x[i+1] = 2*a[i] - x[i]

print(' '.join(map(str, map(int, x))))

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

n = int(input())
a = [int(i) for i in input().split()] 
ans = np.array(a)

s = (n,n)
M = np.matrix(np.zeros(s))
for i in range(n):
    vec = np.zeros(n)
    vec[i]=1/2
    if i == (n-1):
        vec[0]=1/2
    else:
        vec[i+1]=1/2
    M[i] = vec
ans = (np.linalg.inv(M)*(ans.reshape(-1,1)))
print(' '.join(map(str, ans.T.tolist()[0])))

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

n = int(input())
a = [int(i) for i in input().split()] 
ans = np.array(a)
x = np.zeros(n)

s = (n,n)
M = np.matrix(np.zeros(s))
for i in range(n):
    vec = np.zeros(n)
    vec[i]=1/2
    if i == (n-1):
        vec[0]=1/2
    else:
        vec[i+1]=1/2
    M[i] = vec
ans = (np.linalg.inv(M)*(ans.reshape(-1,1)))
print(' '.join(map(str, map(int, ans.T.tolist()[0]))))
Problem p02879 (python)

Fixed submission:
A, B = map(int, input().split())

if (1 <= A <= 9) and (1 <= B <= 9):
  print( A * B )
else: print( -1 )

Buggy submission (verdict: Runtime Error):
A, B = map(int, input().split())

if (1 <= A <= 9) and (1 <= B <= 9):
  return A * B
else: return -1
Problem p02829 (python)

Fixed submission:
import math
from math import ceil
from math import factorial
from collections import Counter
from operator import itemgetter
import bisect
ii = lambda: int(input())
iia = lambda: list(map(int,input().split()))
isa = lambda: list(input().split())

a = ii()
b = ii()

print(6-a-b)

Buggy submission (verdict: Runtime Error):
from math import ceil
from math import factorial
from collections import Counter
from operator import itemgetter
from math import gcd
import bisect
ii = lambda: int(input())
iia = lambda: list(map(int,input().split()))
isa = lambda: list(input().split())

a,b = iia()

print(int((a*b)/gcd(a,b)))
Problem p02831 (python)

Fixed submission:
import math
from math import ceil
from math import factorial
from collections import Counter
from operator import itemgetter

def gcd(a,b):
	if(b==0):
		return a
	return gcd(b,a%b)
import bisect
ii = lambda: int(input())
iia = lambda: list(map(int,input().split()))
isa = lambda: list(input().split())

a,b = iia()

print(int((a*b)/gcd(a,b)))

Buggy submission (verdict: Runtime Error):
from math import ceil
from math import factorial
from collections import Counter
from operator import itemgetter
from math import gcd
import bisect
ii = lambda: int(input())
iia = lambda: list(map(int,input().split()))
isa = lambda: list(input().split())

a,b = iia()

print(int((a*b)/gcd(a,b)))

Buggy submission (verdict: Runtime Error):
import math
from math import ceil
from math import factorial
from collections import Counter
from operator import itemgetter
from math import gcd
import bisect
ii = lambda: int(input())
iia = lambda: list(map(int,input().split()))
isa = lambda: list(input().split())

a,b = iia()

print(int(a*b/gcd(a,b)))
Problem p02948 (python)

Fixed submission:
from heapq import *

n, m = map(int, input().split())
abab = [list(map(int, input().split())) for _ in range(n)]
bites = [[] for _ in range(m)]
for a, b in abab :
    if a <= m : bites[a-1].append(-b)
    
ans = 0
board = []
for bite in bites:
    for b in bite : heappush(board, b)
    if board : ans -= heappop(board)
print(ans)

Buggy submission (verdict: Runtime Error):
from operator import itemgetter
n, m = map(int, input().split())
abab = [list(map(int, input().split())) for _ in range(n)]
abab = sorted(sorted(abab, key=itemgetter(0), reverse=True), key=itemgetter(1), reverse=True)

gyara = [0 for _ in range(m+1)]

def index(a) :
    if a > m:
        return m+1 
    if gyara[a] :
        return index(a+1)
    else :
        return a

for a, b in abab :
    i = index(a)
    if i <= m :
        gyara[i] = b

print(sum(gyara))
Problem p02984 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))

# m0 + m1 + m2 + m3 + m4 = d0 + d1 + d2 + d3 + d5
# d0 = (m0 + m1)//2
# d1 = (m1 + m2)//2
# d2 = (m2 + m3)//2
# d3 = (m3 + m4)//2
# d4 = (m4 + m0)//2
# m0 =  d0 - d1 + d2 - d3 + d4
# m1 =  d0 + d1 - d2 + d3 - d4
# m2 = -d0 + d1 + d2 - d3 + d4
# m3 =  d0 - d1 + d2 + d3 - d4
# m4 = -d0 + d1 - d2 + d3 + d4   
s = sum(a)
p = [0 for _ in range(n)]
q = [0 for _ in range(n+1)]
for i in range(n) :
    if i>1 :
        p[i] = p[i-2] + a[i-2]
    q[n-i-2] = q[n-i] + a[n-i-1]

print(*[s-2*p[i]-2*q[i] for i in range(n)])

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))

# m0 + m1 + m2 + m3 + m4 = d0 + d1 + d2 + d3 + d5
# d0 = (m0 + m1)//2
# d1 = (m1 + m2)//2
# d2 = (m2 + m3)//2
# d3 = (m3 + m4)//2
# d4 = (m4 + m0)//2
# m0 =  d0 - d1 + d2 - d3 + d4
# m1 =  d0 + d1 - d2 + d3 - d4
# m2 = -d0 + d1 + d2 - d3 + d4
# m3 =  d0 - d1 + d2 + d3 - d4
# m4 = -d0 + d1 - d2 + d3 + d4   

b = [a[i:]+a[:i] for i in range(n)]
print(*[sum(b[::2])-sum(b[1::2]) for i in range(n)])
Problem p02990 (python)

Fixed submission:
n, k = map(int, input().split())


def comb(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range( 2, n + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


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

Buggy submission (verdict: Runtime Error):
import scipy

n, k = list(map(int, input().split()))
dekai = 10**9+7

def mycomb(a, b) :
    return int(scipy.special.comb(a, b))%dekai

def usless(tukau, i) :
    if tukau-i+1 < 0 :
        return 0
    else :
        return mycomb(k-1, i-1)*mycomb(tukau-1,i-2)

def sousa(i) :
    if i == 1 :
        return n-k+1
    else :
        wa = 0
        for utan in range(n-k+1) :
            for satan in range(n-k+1-utan) :
                tukau = n-k-utan-satan
                wa += usless(tukau, i)
        return wa%dekai

for ii in range(k) :
    print(sousa(ii+1))

Buggy submission (verdict: Runtime Error):
import scipy as sp

n, k = list(map(int, input().split()))
dekai = 10**9+7

def mycomb(a, b) :
    return int(sp.special.comb(a, b))%dekai

def usless(tukau, i) :
    if tukau-i+1 < 0 :
        return 0
    else :
        return mycomb(k-1, i-1)*mycomb(tukau-1,i-2)

def sousa(i) :
    if i == 1 :
        return n-k+1
    else :
        wa = 0
        for utan in range(n-k+1) :
            for satan in range(n-k+1-utan) :
                tukau = n-k-utan-satan
                wa += usless(tukau, i)
        return wa%dekai

for ii in range(k) :
    print(sousa(ii+1))

Buggy submission (verdict: Runtime Error):
from scipy.special import comb

n, k = list(map(int, input().split()))
dekai = 10**9+7

def mycomb(a, b) :
    return int(comb(a, b))%dekai

def usless(tukau, i) :
    if tukau-i+1 < 0 :
        return 0
    else :
        return mycomb(k-1, i-1)*mycomb(tukau-1,i-2)

def sousa(i) :
    if i == 1 :
        return n-k+1
    else :
        wa = 0
        for utan in range(n-k+1) :
            for satan in range(n-k+1-utan) :
                tukau = n-k-utan-satan
                wa += usless(tukau, i)
        return wa%dekai

for ii in range(k) :
    print(sousa(ii+1))
Problem p03013 (python)

Fixed submission:
from functools import lru_cache
from sys import setrecursionlimit

n, m = map(int, input().split())
a = set(int(input()) for _ in range(m))

mod = 10**9+7
setrecursionlimit(mod)

@lru_cache(maxsize=n)
def stairway(i) :
    if i in a :
        return 0
    elif i == 0 :
        return 1
    elif i == 1 :
        return stairway(0)
    else :
        return (stairway(i-1)+stairway(i-2))%mod
    
print(stairway(n))

Buggy submission (verdict: Runtime Error):
from functools import lru_cache

n, m = map(int, input().split())
a = set(int(input()) for _ in range(m))

mod = 10**9+7

@lru_cache(maxsize=n)
def stairway(i) :
    if i in a :
        return 0
    elif i == 0 :
        return 1
    elif i == 1 :
        return stairway(0)
    else :
        return (stairway(i-1)+stairway(i-2))%mod
    
print(stairway(n))
Problem p03038 (python)

Fixed submission:
from operator import itemgetter

n, m = map(int, input().split())
aa = list(map(int, input().split()))
bcbc = [list(map(int, input().split())) for _ in range(m)]
bcbc.extend([[1, a] for a in aa])
bcbc.sort(key=itemgetter(1), reverse=True)

count = 0
s = 0
for b, c in bcbc :
    if count + b >= n :
        b = n - count
    count += b
    s += b*c
    if count == n :
        break
print(s)

Buggy submission (verdict: Runtime Error):
#D
import sys
sys.setrecursionlimit(200000)

n, m = list(map(int, input().split()))
alist = list(map(int, input().split()))
alist.sort()

def inserter(key, list1) :
    if list1 == [] :
        return [key]
    elif list1[0][1] < key[1] :
        return [key] + list1
    else :
        return [list1[0]] + inserter(key, list1[1:])
def rewriter(list1, list2) :
    if list1 == [] :
        return []
    elif list2 == [] :
        return list1
    else :
        return [max(list1[0], list2[0])] + rewriter(list1[1:], list2[1:])
    
bclist = []
for i in range(m) :
    bc = list(map(int, input().split()))
    bclist = inserter(bc, bclist)
rwlist = []
for j in len(bclist) :
    if j < len(alist) :
        rwlist += [j[1]] * j[0]
    else :
        break
ans = rewriter(alist, rwlist)
print(sum(ans))

Buggy submission (verdict: Runtime Error):
#D
n, m = list(map(int, input().split()))
alist = list(map(int, input().split()))
alist.sort()
def inserter(key, list1) :
    if list1 == [] :
        return [key]
    elif list1[0][1] > key[1] :
        return [key] + list1
    else :
        return [list1[0]] + inserter(key, list1[1:])
def rewriter(list1, list2) :
    if list1 == [] :
        return []
    elif list2 == [] :
        return list1
    else :
        return [max(list1[0], list2[0])] + rewriter(list1[1:], list2[1:])
bclist = []
for i in range(m) :
    bc = list(map(int, input().split()))
    bclist = inserter(bc, bclist)
bclist.reverse()
rwlist = []
for j in bclist :
    rwlist += [j[1]] * j[0]
ans = rewriter(alist, rwlist)
print(sum(ans))
Problem p03108 (python)

Fixed submission:
from sys import setrecursionlimit
setrecursionlimit(10**5)

n, m = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(m)]

class UnionFind(list) :
    def __init__(self, n) :
        super().__init__(range(n))
        self.dic = {i:1 for i in range(n)}
        self.fubensa = n*(n-1)//2

    def find(self, i) :
        if self[i] == i : return i
        self[i] = self.find(self[i])
        return self[i]

    def union(self, x, y) :
        x = self.find(x)
        y = self.find(y)
        self[y] = x
        if x != y :
            self.fubensa -= self.dic[x]*self.dic[y]
            self.dic[x] += self.dic[y]
            del self.dic[y]

    def sameroot(self, x, y) :
        return self.find(x) == self.find(y)

uf = UnionFind(n)
ans = []
for a, b in reversed(ab) :
    ans.append(uf.fubensa)
    uf.union(a-1, b-1)
    
for a in reversed(ans) :
    print(a)

Buggy submission (verdict: Runtime Error):
n, m = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(m)]

class UnionFind(list) :
    def __init__(self, n) :
        super().__init__(range(n))
        self.dic = {i:1 for i in range(n)}
        self.fubensa = n*(n-1)//2

    def find(self, i) :
        if self[i] == i : return i
        self[i] = self.find(self[i])
        return self[i]

    def union(self, x, y) :
        x = self.find(x)
        y = self.find(y)
        self[y] = x
        if x != y :
            self.fubensa -= self.dic[x]*self.dic[y]
            self.dic[x] += self.dic[y]
            del self.dic[y]

    def sameroot(self, x, y) :
        return self.find(x) == self.find(y)

uf = UnionFind(n)
ans = []
for a, b in reversed(ab) :
    ans.append(uf.fubensa)
    uf.union(a-1, b-1)
    
for a in reversed(ans) :
    print(a)
Problem p03127 (python)

Fixed submission:
from functools import*
d=lambda x,y:d(y%x,x)if y%x else x
_,a=open(0)
print(reduce(d,map(int,a.split())))

Buggy submission (verdict: Runtime Error):
from functools import*
d=lambda x,y:d(x,y%x)if y%x else x
_,a=open(0)
print(reduce(d,map(int,a.split())))
Problem p03253 (python)

Fixed submission:
from math import sqrt
from collections import Counter

n, m = map(int, input().split())

mod = 10**9+7

def factor(n) :
    factors = Counter()
    p = 2
    while p*p <= n :
        while n%p == 0 :
            factors.update([p])
            n //= p
        p += 1
    if n > 1 :
        factors.update([n])
    return factors

def comb(n, r) :
    if n - r < r: r = n - r
    if r < 0: return 0
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

vv = factor(m).values()
ans = 1
for v in vv :
    a = 0
    for i in range(min(n, v)) :
        a += comb(n, i+1)*comb(v-1, i)
    ans *= a
    ans %= mod
print(ans)

Buggy submission (verdict: Runtime Error):
from sympy import factorint

n, m = map(int, input().split())

mod = 10**9+7

def comb(n, r) :
    if n - r < r: r = n - r
    if r < 0: return 0
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

vv = factorint(m).values()
ans = 1
for v in vv :
    a = 0
    for i in range(min(n, v)) :
        a += comb(n, i+1)*comb(v-1, i)
    ans *= a
    ans %= mod
print(ans)
Problem p03426 (python)

Fixed submission:
H, W, D = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
Q = int(input())
LR = [list(map(int, input().split())) for _ in range(Q)]

dp = [None for _ in range(H*W)]
for i, l in enumerate(A) :
    for j, v in enumerate(l) :
        dp[v-1] = (i, j)

def f(p, q) :
    x, y = dp[p]
    i, j = dp[q]
    return abs(x-i)+abs(y-j)

distance = [0 for _ in range(H*W)]
for i in range(H*W) :
    if i<D :
        pass
    else :
        distance[i] = f(i-D, i) + distance[i-D]

for l, r in LR :
    print(distance[r-1]-distance[l-1])

Buggy submission (verdict: Runtime Error):
H,W,D=map(int,input().split());S=H*W;A=[map(int,input().split())for _ in range(H)];Q,*L=open(0);d=[0]*S;e=[0]*S
for i,l in enumerate(A):
 for j,v in enumerate(l):d[v-1]=(i,j)
for i in range(S):
 if i>=D:e[i]=sum(abs(p-q)for p,q in zip(d[i-D],d[i]))+e[i-D]
for i in L:l,r=map(int,i.split());print(e[r-1]-e[l-1])
Problem p02831 (python)

Fixed submission:
import math
a,b = map(int,input().split())
temp = math.gcd(a, b)
ans = a * b // temp
print(ans)

Buggy submission (verdict: Runtime Error):
import math
a,b = map(int,input().split())
temp = math.gcd(a, b)
ans = a * b // temp
print(ans