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

Fixed submission:
N = int(input())
A = list(map(int,input().split(" ")))
B = list(map(int,input().split(" ")))
ans = 0
for i in range(N):
    if A[i] >= B[i]:
        ans += B[i]
    else: 
        if B[i] >= (A[i] + A[i+1]):
            ans += (A[i] + A[i+1])
            A[i+1] = 0
        
        elif B[i] < (A[i] + A[i+1]):
            ans += B[i]
            A[i+1] = (A[i] + A[i+1]) - B[i]
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split(" ")))
B = list(map(int,input().split(" ")))
ans = 0
for i in range(N):
    if A[i] >= B[i]:
        ans += B[i]
    else: 
        if B[i] >= (A[i] + A[i+1]):
            ans += (A[i] + A[i+1])
            A[i+1] = 0
        
        elif B[i] < (A[i] + A[i+1]):
            print(ans)
            ans += B[i]
            print(ans)
            A[i+1] = (A[i] + A[i+1]) - B[i]
    print(A,ans)
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split(" ")))
B = list(map(int,input().split(" ")))
a = sum(A)
ans = 0
for i in range(N):
    tmp = A[i]+A[i+1]-B[i]
    ans = ans + max(0,tmp-A[i+1])
    A[i+1] = min(A[i+1],tmp)
    print(A)

print(a - ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split(" ")))
B = list(map(int,input().split(" ")))
a = sum(A)
ans = 0
for i in range(N):
    tmp = A[i]+A[i+1]-B[i]
    ans = ans + max(0,tmp-A[i+1])
    A[i+1] = min(A[i+1],tmp)
    print(A)

print(a - ans)
Problem p02990 (python)

Fixed submission:
import math
N,K = map(int,input().split(" "))
x = N - K #red ball
for i in range(1,K+1):
    if x+1-i >= 0:
        a = math.factorial(x+1) // (math.factorial(i)*math.factorial(x+1-i))
    else:
        a = 0
    b = math.factorial(K-1) // (math.factorial(i-1)*math.factorial(K-i))
    print(a * b % (10**9+7))

Buggy submission (verdict: Runtime Error):
import math
N,K = map(int,input().split(" "))
x = N - K #red ball
for i in range(1,K+1):
    a = math.factorial(x+1) // (math.factorial(i)*math.factorial(x+1-i))
    b = math.factorial(K-1) // (math.factorial(i-1)*math.factorial(K-i))
    print(a * b % (10**9+7))

Buggy submission (verdict: Runtime Error):
import math
N,K = map(int,input().split(" "))
x = N - K #red ball
for i in range(1,K+1):
    a = math.factorial(x+1) // (math.factorial(i)*math.factorial(x+1-i))
    b = math.factorial(K-1) // (math.factorial(i-1)*math.factorial(K-i))
    print(a * b % (10**9+7))
Problem p03834 (python)

Fixed submission:
A = input()
l = A.split(',')
print(l[0],' ',l[1],' ',l[2],' ')

Buggy submission (verdict: Runtime Error):
A = input()
l = A.split(,)
print(l[0],' ',l[1],' ',l[2],' ')
Problem p02627 (python)

Fixed submission:
S=input()
if S.upper()==S:
  print("A")
else:
  print("a")

Buggy submission (verdict: Runtime Error):
if input().upper()==input():
  print("A")
else:
  print("a")
Problem p02790 (python)

Fixed submission:
a,b=map(int,input().split())
if a<=b:
	print(int(a*(10**(b)-1)/9))
else:
	print(int(b*(10**(a)-1)/9))

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
if a<=b:
  for i in range(b):
    print(a)
else:
    for i in range(a):
    print(b)
Problem p02948 (python)

Fixed submission:
from collections import defaultdict
import heapq
N, M = map(int, input().split())
dct = defaultdict(list)

for i in range(N):
  A, B = map(int, input().split())
  dct[A].append(-B)

h = []
ans = 0
for i in range(1,M+1):
  if dct[i]:
    for item in dct[i]:
      heapq.heappush(h,item)
  if h:
    ans += heapq.heappop(h)

print(-ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
N = int(input())
dct = defaultdict(int)

for i in range(N):
  s = input()
  sorted_s = "".join(sorted(s))
  dct[sorted_s] += 1

ans = 0
for k, v in dct.items():
  ans += v*(v-1)//2

print(ans)
Problem p02598 (python)

Fixed submission:
import sys

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

if k == 0:
    print(max(a))
    sys.exit()

def check(t):
    if t == 0:
        return False
    ans = 0
    for ai in a:
        if ai > t:
            ans += ai // t
    return ans <= k

l = 0
r = 10 ** 9 + 1

while r - l > 1:
    mid = (r + l) // 2
    if check(mid):
        r = mid
    else:
        l = mid

if check(l):
    print(l)
else:
    print(r)

Buggy submission (verdict: Runtime Error):
import sys

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

if k == 0:
    print(max(a))
    sys.exit()

def check(t):
    ans = 0
    for ai in a:
        if ai > t:
            ans += ai // t
    return ans <= k

l = 0
r = 10 ** 9 + 1

while r - l > 1:
    mid = (r + l) // 2
    if check(mid):
        r = mid
    else:
        l = mid

if check(l):
    print(l)
else:
    print(r)

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

def check(t):
    ans = 0
    for ai in a:
        if ai > t:
            ans += ai // t
    return ans <= k

l = 0
r = 10 ** 9 + 1

while r - l > 1:
    mid = (r + l) // 2
    if check(mid):
        r = mid
    else:
        l = mid

if check(l):
    print(l)
else:
    print(r)
Problem p02661 (python)

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

if n % 2:

    ab.sort()
    l = ab[(n+1)//2-1][0]

    ab.sort(key=lambda x:x[1], reverse=True)
    r = ab[(n+1)//2-1][1]

    print(r-l+1)

else:

    a = [ai for ai, bi in ab]
    b = [bi for ai, bi in ab]

    a.sort()
    b.sort()

    ll = a[n//2-1]
    lr = b[n//2-1]

    rl = a[n//2]
    rr = b[n//2]


    print((lr+rr) - (ll+rl) + 1)

Buggy submission (verdict: Runtime Error):
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort()
l = ab[(n+1)//2-1][0]
ab.sort(key=lambda x:x[1], reverse=True)
r = ab[(n+1)//2-1][1]

if n % 2 == 0:
    print(1/0)
print(r-l+1)
Problem p02781 (python)

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

n = input()
k = int(input())

def calc(i, k):
    return comb(len(n) - i - 1, k) * 9 ** k

def cnt(n):
    cnt = 0
    for c in n:
        if c != "0":
            cnt += 1
    return cnt

ans = 0
if cnt(n) == k:
    ans += 1


for i in range(len(n)):
    if int(n[i]) == 0:
        continue
    if len(n)-i > k:
        ans += calc(i, k)
    k -= 1
    if k < 0:
        break
    if len(n)-i > k:
        ans += (int(n[i]) - 1) * calc(i, k)
print(ans)

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

n = input()
k = int(input())

def calc(i, k):
    return comb(len(n) - i - 1, k) * 9 ** k

ans = 0
if len(n) == k:
    ans +=1

for i in range(len(n)):
    if len(n)-i > k:
        ans += calc(i, k)
    k -= 1
    if k < 0:
        break
    ans += (int(n[i]) - 1) * calc(i, k)

print(ans)
Problem p02793 (python)

Fixed submission:
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

#逆元テーブル
mod = 10 ** 9 + 7
N = 1000002
inv_t = [0]+[1]
for i in range(2, N):
  inv_t += [inv_t[mod % i] * (mod - int(mod / i)) % mod]

n = int(input())
a = list(map(int, input().split()))
d = [0 for i in range(1000001)]
for ai in a:
    arr = factorization(ai)
    for i, n in arr:
        d[i] = max(d[i], n)

base = 1
for i, n in enumerate(d):
    base = base * i ** n % mod
ans = 0
for ai in a:
    ans = (ans + base * inv_t[ai]) % mod
print(ans)

Buggy submission (verdict: Runtime Error):
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)
def lcm(a, b):
    return a * b // gcd(a, b)

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

mod = 10 ** 9 + 7
N = n + 2

#逆元テーブル
inv_t = [0]+[1]
for i in range(2, N):
  inv_t += [inv_t[mod % i] * (mod - int(mod / i)) % mod]

base = a[0]
for ai in a:
    base = lcm(base, ai)
ans = 0
for ai in a:
    ans = (ans + base * inv_t[ai]) % mod
print(ans)
Problem p02834 (python)

Fixed submission:
import sys
from collections import deque

input = sys.stdin.readline
n, u, v = map(int, input().split())

E = [[] for i in range(n)]
for i in range(n - 1):
    a, b = map(int, input().split())
    E[a-1].append(b-1)
    E[b-1].append(a-1)

memo = [[0, 0] for i in range(n)]

def dfs(cur, pre, p):
    stack = deque([[cur, pre]])
    while stack:
        cur, pre = stack.pop()
        if pre != -1:
            memo[cur][p] = memo[pre][p] + 1
        for e in E[cur]:
            if e != pre:
                stack.append([e, cur])

dfs(u - 1, - 1, 0)
dfs(v - 1, -1, 1)

# print(memo)
ans = 0
for a, b in memo:
    if a <= b:
        ans = max(ans, b - 1)
print(ans)

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

input = sys.stdin.readline
n, u, v = map(int, input().split())

E = [[] for i in range(n)]
for i in range(n - 1):
    a, b = map(int, input().split())
    E[a-1].append(b-1)
    E[b-1].append(a-1)

memo = [[0, 0] for i in range(n)]

def dfs(cur, pre, dep, p):
    stack = deque([[cur, pre, dep, p]])
    while stack:
        cur, pre, dep, p  = stack.pop()
        memo[cur][p] = dep
        for e in E[cur]:
            if e != pre:
                stack.push(e, cur, dep + 1, p)

dfs(u - 1, - 1, 0, 0)
dfs(v - 1, -1, 0, 1)

# print(memo)
ans = 0
for a, b in memo:
    ans = max(ans, b - 1)
print(ans)

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

input = sys.stdin.readline
n, u, v = map(int, input().split())

E = [[] for i in range(n)]
for i in range(n - 1):
    a, b = map(int, input().split())
    E[a-1].append(b-1)
    E[b-1].append(a-1)

memo = [[0, 0] for i in range(n)]

def dfs(cur, pre, dep, p):
    stack = deque([[cur, pre]])
    memo[cur][p] = dep
    while stack:
        cur, pre = stack.pop()
        for e in E[cur]:
            if e != pre:
                dfs(e, cur, dep + 1, p)

dfs(u - 1, - 1, 0, 0)
dfs(v - 1, -1, 0, 1)

# print(memo)
ans = 0
for a, b in memo:
    ans = max(ans, b - 1)
print(ans)

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

input = sys.stdin.readline
n, u, v = map(int, input().split())

E = [[] for i in range(n)]
for i in range(n - 1):
    a, b = map(int, input().split())
    E[a-1].append(b-1)
    E[b-1].append(a-1)

memo = [[0, 0] for i in range(n)]

def dfs(cur, pre, dep, p):
    stack = deque([[cur, pre]])
    memo[cur][p] = dep
    while stack:
        cur, pre = stack.pop()
        for e in E[cur]:
            if e != pre:
                dfs(e, cur, dep + 1, p)

dfs(u - 1, - 1, 0, 0)
dfs(v - 1, -1, 0, 1)

# print(memo)
ans = 0
for a, b in memo:
    if b - a > 1:
        ans = max(ans, b - 1)
print(ans)
Problem p02863 (python)

Fixed submission:
import sys
input = sys.stdin.readline
n, t = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort()

dp = [[0 for j in range(t+1)] for i in range(n+1)]

for i in range(n):
    for j in range(t+1):
        dp[i+1][j] =  dp[i][j]
    for j in range(t):
        next = min(j + ab[i][0], t)
        dp[i+1] [next] = max(dp[i+1][next], dp[i][j] + ab[i][1])
print(max(dp[n]))

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n, t = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort(key = lambda x:x[1])
dp = [[0 for j in range(t+1)] for i 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])
    for j in range(t):
        if j < t:
            next = min(j + ab[i][0], t)
            dp[i+1] [next] = max(dp[i+1][next], dp[i][j] + ab[i][1])
print(max(dp[n][t]))
Problem p02873 (python)

Fixed submission:
s = input()
a = [-1 for i in range(len(s)+1)]
for i in range(len(s)-1):
    if s[i] == '>' and s[i+1] == "<":
        a[i+1] = 0
if s[0] == "<":
    a[0] = 0
if s[-1] == ">":
    a[-1] = 0
def plus(i):
    j = i -1
    while j >= 0 and s[j] == '>':
        a[j] = max(a[j+1] + 1, a[j])
        j -= 1
    j = i
    if j == len(a) -1:
        return
    while s[j] == '<':
        a[j+1] = max(a[j] + 1, a[j+1])
        j += 1
        if  j == len(a) - 1:
            break
for i in range(len(a)):
    if a[i] == 0:
        plus(i)
print(sum(a))

Buggy submission (verdict: Runtime Error):
s = input()
a = [-1 for i in range(len(s)+1)]
for i in range(len(s)-1):
    if s[i] == '>' and s[i+1] == "<":
        a[i+1] = 0
if s[0] == "<":
    a[0] = 0
if s[-1] == ">":
    a[-1] = 0
def plus(i):
    j = i - 1
    while s[j] == '>':
        a[j] = max(a[j+1] + 1, a[j])
        j -= 1
        if j < 0:
            break
    j = i
    while s[j] == '<':
        a[j+1] = max(a[j] + 1, a[j+1])
        j += 1
        if  j == len(a) - 1:
            break
for i in range(len(a)):
    if a[i] == 0:
        plus(i)
print(sum(a))
Problem p02954 (python)

Fixed submission:
s = input()
s = s.replace("RL", "*")
i = 0
rls = []
n = 0
m = 0
for c in s:
  if c == "R":
    n += 1
  if c == "*":
    r = (n + 1) // 2
    l = n + 1 - r
    rls.append([l, r])
    n = 0
m = 0
i = 1
for c in reversed(s):
  if c == "L":
    m += 1
  if c == "*":
    l = (m + 1) // 2
    r = m + 1 - l
    rls[-i][0] += l
    rls[-i][1] += r
    i += 1
    m = 0
ans = []
i = 0
for c in s:
  if c == "*":
    ans.extend(rls[i])
    i += 1
  else:
    ans.append(0)
print(" ".join([str(c) for c in ans]))

Buggy submission (verdict: Runtime Error):
s = input()
s = s.replace("RL", "*")
i = 0
rls = []
n = 0
m = 0
for c in s:
  if c == "R":
    n += 1
  if c == "*":
    r = (n + 1) // 2
    l = n + 1 - r
    rls.append([l, r])
    n = 0
m = 0
i = 1
for c in reversed(s):
  if c == "L":
    m += 1
  if c == "*":
    l = (m + 1) // 2
    r = m + 1 - l
    rls[-i][0] += l
    rls[-i][1] += r
    i += 1
    m = 0
ans = []
i = 0
for c in s:
  if c == "*":
    ans = ans.extend(rls[i])
    i += 1
  else:
    ans.append(0)
print(" ".join([str(c) for c in ans]))
Problem p02955 (python)

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

# 約数列挙
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

ans = 1

for div in make_divisors(sum(a)):
    mod_div = []
    for ai in a:
        mod_div.append(ai % div)
    mod_div.sort()

    tmp_p = n * div - sum(mod_div)
    tmp_m = 0

    for i, x in enumerate(mod_div):
        tmp_m += x
        tmp_p -= div - x
        if tmp_m == tmp_p and tmp_m <= k:
            ans = max(div, ans)

print(ans)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = [int(x) for x in input().split()]
for i in range(max(a) + k +1):
  s = [x % i for x in a]
  if sum(s) % i == 0:
    print(i)
    break
Problem p02990 (python)

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

def kai(a):
    res = 1
    for i in range(1, a+1):
        res = res * i
    return res

def cmb(n, r):
    return kai(n) // kai(r) // kai(n-r)
#
# for i in range(1, k + 1):
#     nao = cmb(k - 1, i - 1)
#     nak = cmb(n - k + 1,  i)
#     print(nao * nak % N)

ans = 0
for i in range(1, k+1):
    if i == 1:
        ans = cmb(k - 1, i - 1) * cmb(n - k + 1,  i)
    print(ans  % N)
    ans = ans * (k - i) // i * (n - k - i + 1) // (i + 1)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
d = {i+1 : [] for i  in range(n)}
for _ in range(m):
    u, v = map(int, input().split())
    d[u].append(v)
s, t = map(int, input().split())
q = set([s])
visited = set([s])
c = 1
def solve():
    global visited, c, q
    while True:
        for v in list(q):
            q.remove(v)
            es =set([e3 for e1 in d[v] for e2 in d[e1] for e3 in d[e2] if not e3 in visited])
            if t in es:
                return c
            else:
                visited |= es
                q |= es
        if not len(q):
            return -1
        c += 1
print(solve())
Problem p03012 (python)

Fixed submission:
n = int(input())
ws = list(map(int, input().split()))
print(min([abs(sum(ws[:i+1]) - sum(ws[i+1:])) for i in range(len(ws) - 1)]))

Buggy submission (verdict: Runtime Error):
n = int(input())
ws = list(map(int, input().split()))
print(min([abs(sum(ws[:i+1]) - sum(ws[i+1:])) for i in range(len(ws - 1))])
Problem p03038 (python)

Fixed submission:
n, m = map(int, input().split())
a = list(map(int, input().split()))
p = [list(map(int, input().split())) for i in range(m)]
cand = sorted(a)
ps =  sorted(p, key = lambda x : x[1], reverse = True)
i = 0
ans = 0
def calc():
    global i
    for b, c in ps:
        for d in range(b):
            if i + d == len(cand):
                return sum(cand)
            if cand[i + d] < c:
                cand[i + d] = c
            else:
                return sum(cand)
        i += b
    return sum(cand)
print(calc())

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = list(map(int, input().split()))
p = [list(map(int, input().split())) for i in range(m)]
cand = sorted(a)
ps =  sorted(p, key = lambda x : x[1], reverse = True)
i = 0
ans = 0
def calc():
    global i
    for b, c in ps:
        for d in range(b):
            if cand[i + d] < c:
                cand[i + d] = c
            else:
                return sum(cand)
        i += b
    return sum(cand)
print(calc())
Problem p03045 (python)

Fixed submission:
import sys
from collections import deque
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
n, m = map(int, input().split())
memo = set(list(range(n)))
E = [[] for i in range(n)]
for i in range(m):
    x, y, z = map(int, input().split())
    E[x-1].append(y-1)
    E[y-1].append(x-1)
def dfs(cur, pre):
    stack = deque([[cur, pre]])
    while stack:
        cur, pre = stack.pop()
        if pre != -1:
            memo.discard(cur)
        for e in E[cur]:
            if e != pre and e in memo:
                stack.append([e, cur])
ans = 0
while len(memo):
    cur = memo.pop()
    dfs(cur, -1)
    ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
from collections import deque
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
n, m = map(int, input().split())
memo = set(list(range(n)))
E = [[] for i in range(n)]
for i in range(m):
    x, y, z = map(int, input().split())
    E[x-1].append(y-1)
    E[y-1].append(x-1)
def dfs(cur, pre):
    stack = deque([[cur, pre]])
    while stack:
        cur, pre = stack.pop()
        memo.discard(cur)
        for e in E[cur]:
            if e != pre and e in memo:
                stack.append([e, cur])
ans = 0
for i in range(n):
    if i in memo:
        dfs(cur, -1)
        ans += 1
print(ans)
Problem p03077 (python)

Fixed submission:
n = int(input())
a = [int(input()) for i in range(5)]
ma = min(a)
s = n // ma
if n % ma:
  s += 1
print(4 + s)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10000)
n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

ps = [n, 0, 0, 0, 0, 0]
ts = [a, b, c, d, e]
t = 0

def move(ps, t):
    if ps[len(ps)-1] == n:
        return print(t)
    ds = [0, 0, 0, 0, 0, 0]
    for i in range(len(ps) - 1):
        if ps[i] > 0:
            diff = min(ts[i], ps[i])
            ds[i] -= diff
            ds[i + 1] += diff
    move([ps[j] + ds[j]  for j in range(len(ds))], t +1)

move(ps, t)
Problem p03221 (python)

Fixed submission:
n, m = map(int, input().split())
cs = []
cd = {}
ps = {}
for _ in range(m):
  p, y = map(int, input().split())
  cs.append([p, y])
  if p in ps:
    ps[p].append(y)
  else:
    ps[p] = [y]
    
for p in ps:
  v = sorted(ps[p])
  for i, y in enumerate(v):
    cd[y] = i + 1
[print('{:06}{:06}'.format(c[0], cd[c[1]])) for c in cs]

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
cs = []
ps = {}
for _ in range(m):
  p, y = map(int, input().split())
  cs.appenyd([y, p])
css = sorted(cs)
for c in css:
  if c[1] in ps:
    ps[c[1]].append(c[0])
  else:
    ps[c[1]] = [c[0]]
[print('{:06}{:06}'.format(c[1], ps[c[1]].index(c[0])+1))for c in cs]
Problem p03253 (python)

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

mod = 10 ** 9 + 7
N = 200000

#逆元テーブル
inv_t = [0]+[1]
for i in range(2, N):
  inv_t += [inv_t[mod % i] * (mod - int(mod / i)) % mod]

#階乗計算
kai = [1, 1]
rev_kai = [1, inv_t[1]]
for i in range(2, N):
	kai.append(kai[-1] * i % mod)
	rev_kai.append(rev_kai[-1] * inv_t[i] % mod)

# コンビネーション計算
def cmb(n, r):
	return kai[n] * rev_kai[r] * rev_kai[n-r] % mod

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

ans = 1

for _, cnt in factorization(m):
    if _ == 1:
        break
    ans = ans * cmb(cnt + n - 1, n - 1) % mod

print(ans)

Buggy submission (verdict: Runtime Error):
from scipy.special import comb as cmb
n, m = map(int, input().split())

mod = 10 ** 9 + 7
N = 100005

# #逆元テーブル
# inv_t = [0]+[1]
# for i in range(2, N):
#   inv_t += [inv_t[mod % i] * (mod - int(mod / i)) % mod]

# #階乗計算
# kai = [1, 1]
# rev_kai = [1, inv_t[1]]
# for i in range(2, N):
# 	kai.append(kai[-1] * i % mod)
# 	rev_kai.append(rev_kai[-1] * inv_t[i] % mod)

# # コンビネーション計算
# def cmb(n, r):
# 	return kai[n] * rev_kai[r] * rev_kai[n-r] % mod

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

ans = 1

for _, cnt in factorization(m):
    ans = ans * int(cmb(cnt + n - 1, n - 1, exact=True)) % mod

print(ans)
Problem p03346 (python)

Fixed submission:
import sys
input = sys.stdin.readline
n = int(input())
memo = [0 for i in range(n)]
for i in range(n):
  memo[int(input())-1] = i
cand = 0
tmp = 0
for n1, n2 in zip(memo[:], memo[1:]):
  if n2 > n1:
    tmp += 1
    if tmp > cand:
      cand = tmp
  else:
    tmp = 0
print(n - cand - 1)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n = int(input())
memo = [0 for i in range(n)]
for i in range(n):
  memo[int(input())-1] = i
cand = 0
tmp = 0
for n1, n2 in range(n - 1):
  if n2 > n1:
    tmp += 1
    if tmp > cand:
      cand = tmp
  else:
    tmp = 0
print(n - cand - 1)