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

Fixed submission:
import math

N, M = map(int, input().split())
MOD = 10**9+7

def trial_division(n):
  #素因数を格納するリスト
  factor = []
  #2から√n以下の数字で割っていく
  tmp = int(math.sqrt(n)) + 1
  for num in range(2,tmp):
    cnt = 0
    while n % num == 0:
      n //= num
      cnt += 1 
    if cnt != 0:
      factor.append(cnt)
  #リストが空ならそれは素数
  if not factor:
    return []
  else:
    if n != 1:
      factor.append(1)
    return factor

from operator import mul
from functools import reduce

def cmb(n,r):
  r = min(n-r,r)
  if r == 0: return 1
  over = reduce(mul, range(n, n - r, -1))
  under = reduce(mul, range(1,r + 1))
  return over // under

ans = 1
cnts = trial_division(M)
for cnt in cnts:
  ans = ans * (cmb(cnt+N-1, cnt))%MOD

# print(cnts)
print(ans)

Buggy submission (verdict: Runtime Error):
import math

N, M = map(int, input().split())
MOD = 10**9+7

def trial_division(n):
  #素因数を格納するリスト
  factor = []
  #2から√n以下の数字で割っていく
  tmp = int(math.sqrt(n)) + 1
  for num in range(2,tmp):
    cnt = 0
    while n % num == 0:
      n //= num
      cnt += 1 
    if cnt != 0:
      factor.append(cnt)
  #リストが空ならそれは素数
  if not factor:
    return 'prime number'
  else:
    if n != 1:
      factor.append(1)
    return factor

from operator import mul
from functools import reduce

def cmb(n,r):
  r = min(n-r,r)
  if r == 0: return 1
  over = reduce(mul, range(n, n - r, -1))
  under = reduce(mul, range(1,r + 1))
  return over // under

ans = 1
cnts = trial_division(M)
for cnt in cnts:
  ans = ans * (cmb(cnt+N-1, cnt))%MOD

print(ans)
Problem p03317 (python)

Fixed submission:
import math

N, K = map(int, input().split())
nums = list(map(int, input().split()))
print(math.ceil((len(nums)-1)/(K-1)))

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

min_idx = 0
for idx in range(N):
  if A[idx] < A[min_idx]:
    min_idx = idx
ans = 10**5
for idx in range(K):
  left = min_idx - K + idx
  right = min_idx + idx
  if min_idx - K + idx < 0:
    continue
  if min_idx - K + idx >= N:
    break
  sum_cnt = 1
  if (N-right)%(K-1) == 0:
    sum_cnt += (N-right)//(K-1)
  else:
    sum_cnt += (N-mright)//(K-1)+1
  if left%(K-1) == 0:
    sum_cnt += left//(K-1)
  else:
    sum_cnt += left//(K-1) + 1
  ans = min(ans, sum_cnt)
print(ans)

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

min_idx = 0
for idx in range(N):
  if A[idx] < A[min_idx]:
    min_idx = idx
ans = 0
if (N-min_idx)%(K-1) == 0:
  ans += (N-min_idx)//(K-1)
else:
  ans += (N-min_idx)//(K-1)+1
if min_idx%(K-1) == 0:
  ans += min_idx//(K-1)
else:
  ans += min_idx//(K-1) + 1
print(ans)

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

min_idx = 10**5
for idx in range(N):
  if A[idx] < A[min_idx]:
    min_idx = idx
ans = 0
if (N-idx)%(K-1) == 0:
  ans += (N-idx)//(K-1)
else:
  ans += (N-idx)//(K-1)+1
if idx%(K-1) == 0:
  ans += idx//(K-1)
else:
  ans += idx//(K-1) + 1
print(ans)

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

A = 10**5
min_idx = 0
for idx in range(N):
  if A[idx] < A[min_idx]:
    min_idx = idx
ans = 0
if (N-idx)%(K-1) == 0:
  ans += (N-idx)//(K-1)
else:
  ans += (N-idx)//(K-1)+1
if idx%(K-1) == 0:
  ans += idx//(K-1)
else:
  ans += idx//(K-1) + 1
print(ans)
Problem p03327 (python)

Fixed submission:
N = int(input())
if N >= 1000:
  print('ABD')
else:
  print('ABC')

Buggy submission (verdict: Runtime Error):
N = int(input())
INF = 10**6
dp = [INF] * (max(9, N))
for i in range(10):
  if  0 < i < 6:
    dp[i] = i
  elif i < 9:
    dp[i] = i%6+1
for i in range(N):
  n = m = 1
  while i+9**n <= N:
    dp[i+9**n] = min(dp[i+9**n], dp[i] + 1)
    n += 1
  while i+6**m <= N:
    dp[i+6**m] = min(dp[i+6**m], dp[i] + 1)
    m += 1
print(dp[N])
Problem p03329 (python)

Fixed submission:
N = int(input())
INF = 10**6
dp = [INF] * (max(9, N)+1)
dp[0] = 0
for i in range(N):
  n = m = 0
  while i+9**n <= N:
    dp[i+9**n] = min(dp[i+9**n], dp[i] + 1)
    n += 1
  while i+6**m <= N:
    dp[i+6**m] = min(dp[i+6**m], dp[i] + 1)
    m += 1
print(dp[N])

Buggy submission (verdict: Runtime Error):
N = int(input())
INF = 10**6
dp = [INF] * (max(9, N))
for i in range(10):
  if  0 < i < 6:
    dp[i] = i
  elif i < 9:
    dp[i] = i%6+1
for i in range(N):
  n = m = 1
  while i+9**n <= N:
    dp[i+9**n] = min(dp[i+9**n], dp[i] + 1)
    n += 1
  while i+6**m <= N:
    dp[i+6**m] = min(dp[i+6**m], dp[i] + 1)
    m += 1
print(dp[N])

Buggy submission (verdict: Runtime Error):
N = int(input())
INF = 10**6
dp = [INF] * (N+1)
for i in range(9):
  if i < 6:
    dp[i] = i
  elif i < 9:
    dp[i] = i%6+1

for i in range(N):
  n = m = 1
  while i+9*n <= N:
    dp[i+9*n] = min(dp[i+9*n], dp[i] + 1)
    n += 1
  while i+6*m <= N:
    dp[i+6*m] = min(dp[i+6*m], dp[i] + 1)
    m += 1
print(dp[N])

Buggy submission (verdict: Runtime Error):
N = int(input())
INF = 10**6
dp = [INF] * (N+1)
for i in range(10):
  if i < 6:
    dp[i] = i
  elif i < 9:
    dp[i] = i%6+1
  else:
    dp[i] = 1
for i in range(N):
  n = m = 1
  while i+9*n > N:
    dp[i+9*n] = min(dp[i+9*n], dp[i] + 1)
    n += 1
  while i+6*m > N:
    dp[i+6*m] = min(dp[i+6*m], dp[i] + 1)
    m += 1
print(dp[N])

Buggy submission (verdict: Runtime Error):
N = int(input())
INF = 10**6
dp = [INF] * (max(9, N)+1)
for i in range(10):
  if  0 < i < 6:
    dp[i] = i
  elif i < 9:
    dp[i] = i%6+1
  else:
    dp[i] = 1
for i in range(N):
  n = m = 1
  for j in range(1, 6):
    dp[i+j] = min(dp[i+j], dp[i] + j)
  while i+9**n <= N:
    dp[i+9**n] = min(dp[i+9**n], dp[i] + 1)
    n += 1
  while i+6**m <= N:
    dp[i+6**m] = min(dp[i+6**m], dp[i] + 1)
    m += 1
print(dp[N])

Buggy submission (verdict: Runtime Error):
N = int(input())
INF = 10**6
dp = [INF] * (N+1)
for i in range(10):
  if  0 < i < 6:
    dp[i] = i
  elif i < 9:
    dp[i] = i%6+1
  else:
    dp[i] = 1
for i in range(N):
  n = m = 1
  while i+9**n <= N:
    dp[i+9**n] = min(dp[i+9**n], dp[i] + 1)
    n += 1
  while i+6**m <= N:
    dp[i+6**m] = min(dp[i+6**m], dp[i] + 1)
    m += 1
print(dp[N])

Buggy submission (verdict: Runtime Error):
N = int(input())

d_list = [1]

a = 1
while True;
  if 6**a <= N:
    d_list.append(6**a)
    a += 1
  else:
    break
a = 1
while True:
  if 9**a <= N:
    d_list.append(9**a)
    a += 1
  else:
    break
d_list.sort(key=lambda x:-x)

rest = N
cnt = 0
while True:
  if rest < 6:
    cnt = rest
    print(cnt)
  else:
    for num in d_list:
      if rest >= num:
        cnt += 1
        rest -= num
        break
Problem p03345 (python)

Fixed submission:
A, B, C, K = map(int, input().split())
if K%2 == 0:
  print(A-B)
else:
  print(B-A)

Buggy submission (verdict: Runtime Error):
A, B, C, K = map(int, input().split())
if K%2 = 0:
  print(A-B)
else:
  print(B-A)
Problem p03745 (python)

Fixed submission:
N = int(input())
nums = list(map(int, input().split()))
upper = True
lower = True
before = nums[0]
answer = 0
for i, num in enumerate(nums):
  if before < num:
    lower = False
  elif before > num:
    upper = False
  before = num
  if not upper and not lower:
    answer += 1
    upper = True
    lower = True
print(answer+1)

Buggy submission (verdict: Runtime Error):
N = int(input())
nums = list(map(iunt, input().split()))
upper = True
lower = True
before = nums[0]
answer = 0
for i, num in enumerate(nums):
  if before < num:
    lower = False
  elif before > num:
    upper = False
  before = num
  if not upper and not lower:
    answer += 1
    upper = True
    lower = True
print(answer+1)
Problem p03775 (python)

Fixed submission:
N = int(input())
last = N
for num in range(1, N+1):
  if num**2 > N:
    print(len(str(last)))
    break
  elif num**2 == N:
    print(len(str(num)))
    break
  else:
    if N%num == 0:
      last = N//num

Buggy submission (verdict: Runtime Error):
N = int(input())
last = N
for num in range(1, N):
  if num**2 > N:
    print(len(str(last)))
    break
  elif num**2 == N:
    print(len(str(num)))
    break
  else
    if N%num == 0:
      last = N//num
Problem p02577 (python)

Fixed submission:
import collections 

N = input()
D = collections.Counter(N)
ret = 0
for c in D.keys():
  ret += int(c) * D[c]
  ret = ret % 9
  
if ret  == 0:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
N = input()
ret = 0
for c in N:
  ret += (ret + int(c)) % 9
  
if ret  == 0:
  print(Yes)
else:
  print(No)

Buggy submission (verdict: Runtime Error):
N = input()
ret = 0
for c in N:
  ret += ret + int(c) % 9

if ret % 9 == 0:
  print(Yes)
else:
  print(No)
Problem p02622 (python)

Fixed submission:
ret = 0
S = input()
T = input()
print(len([S[i] for i in range(len(S)) if S[i] != T[i]]))

Buggy submission (verdict: Runtime Error):
ret = 0
S = input()
T = input()
print(len[S[i] for i in range(len(S)) if S[i] != T[i]])
Problem p02693 (python)

Fixed submission:
K = int(input())
A, B = map(int, input().split())
 
l = 0
ret = 'NG'
while l <= B:
  if l >= A:
    ret = 'OK'
  l += K
  
print(ret)

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

l = 0
ret = 'NG"
while l <= B:
  if l >= A:
    ret = 'OK'
  l += K
  
print(ret)
Problem p02723 (python)

Fixed submission:
S = input()
 
if len(S) >= 6:
    if S[2]==S[3] and S[4]==S[5]:
        ret = 'Yes'
    else:
        ret = 'No'
else:
    ret = 'No'
print(ret)

Buggy submission (verdict: Runtime Error):
S = input()S = input()

if len(S) >= 6:
    if S[2]==S[3] and S[4]==S[5]:
        ret = 'Yes'
    else:
        ret = 'No'
else:
    ret = 'No'
print(ret)
Problem p02729 (python)

Fixed submission:
N, M = map(int, input().split())
ret = N * (N - 1) // 2 + M * (M - 1)// 2
print(ret)

Buggy submission (verdict: Runtime Error):
N, S = map(int, input().split())
A = list(map(int, input().split()))
MOD = 998244353
L = 0
R = 0
ret = 0

while R < N:
  if L > R:
    R = L
  if sum(A[L:R + 1]) < S:
    R += 1
  elif sum(A[L:R + 1]) > S:
    L += 1
  elif sum(A[L:R + 1]) == S:
    ret += (L + 1) * (N - R - 1) % MOD
    R += 1
print(ret)
Problem p02790 (python)

Fixed submission:
a,b = map(int, input().split())
if a < b:
  print(str(a) * b)
else:
  print(str(b) * a)

Buggy submission (verdict: Runtime Error):
a,b = map(int, input().split())
print str(min(a**b, b**a))
Problem p02829 (python)

Fixed submission:
print(6 - int(input())-int(input()))

Buggy submission (verdict: Runtime Error):
N = int(input())
A=[]  
A=[int(x) for x in input().split()]
num = 1
count = 0
for i in range(N):
  if A[i] == num:
    num += 1
  else:
    count += 1
if count >= N-1:
  print(-1)
else:
  print(count)

Buggy submission (verdict: Runtime Error):
N,S = map(int, input().split())
tmp = 1
a = 2
while (True):
  if N % a == 0 and S % a == 0:
    N,S = int(N / a), int(S / a)
    tmp *= a
    a = 1
  a += 1
  if N / 2 <= a or S / 2 <= a:
    break
print(tmp * S * N)

Buggy submission (verdict: Runtime Error):
N = int(input())
tmp = input()
S,T =tmp.split()
out = ''
for i in range(N):
  out += S[i] + T[i]
print(out)
Problem p03011 (python)

Fixed submission:
p,q,r = map(int,input().split())


ABC = p + q
BCA = q + r
CAB = r + p

min = ABC
if min > BCA:
  min = BCA
  
if min > CAB:
  min = CAB

print(min)

Buggy submission (verdict: Runtime Error):
p = input('P:')
q = input('Q:')
r = input('R:')

ABC = p + q
BCA = q + r
CAB = r + p

min = ABC
if min > BCA:
  min = BCA
  
if min > CAB:
  min = CAB

print(min)
Problem p02594 (python)

Fixed submission:
print(["No","Yes"][int(input())>=30])

Buggy submission (verdict: Runtime Error):
print(["No","Yes"][int(input)>=30])
Problem p02622 (python)

Fixed submission:
s = input()
t = input()
print(sum([1 for x, y in zip(s, t) if x != y]))

Buggy submission (verdict: Runtime Error):
s = list(input())
t = list(input())
print(sum([1 for x, y in zip(s, t) if x != y])
Problem p02753 (python)

Fixed submission:
s= input()
if "AB" in s or "BA" in s:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
fun main()
{
    val given = readLine()!!
    println(if ( given.contains("AB") || given.contains("BA")) "Yes" else "No")
}

Buggy submission (verdict: Runtime Error):
if len(set(input())==1:
       print("NO")
else:
       print("YES")
Problem p02777 (python)

Fixed submission:
'''
red blue
3 4
red
'''
a, b = [x for x in input().split()]
an, bn = [int(x) for x in input().split()]
threw = input()
if threw == a:an -= 1
else:
    bn -= 1
print(an, bn)

Buggy submission (verdict: Runtime Error):
'''
red blue
3 4
red
'''
a, b = [x for x in input().split()]
an, bn = [int(x) for x in input().split()]
threw = input()
if threw == a:an -= 1
  else:
    bn -= 1
print(an, bn)
Problem p02779 (python)

Fixed submission:
'''
Sample Input 1

5
2 6 1 4 5
Sample Output 1

YES
'''
lens = int(input())
arrs = [int(x) for x in input().split()]
print(["NO", "YES"][len(arrs) == len(set(arrs))])

Buggy submission (verdict: Runtime Error):
'''
Sample Input 1 

5
2 6 1 4 5
Sample Output 1 

YES
'''
lens = int(input())
arrs = [int(x) for x in input(),split()]
print(["NO", "YES"][len(arrs) == len(set(arrs))])
Problem p02790 (python)

Fixed submission:
a, b = [x for x in input().split()]
print(sorted([a * int(b), b * int(a)])[0])

Buggy submission (verdict: Runtime Error):
# 7 7
a, b = [xfor x in input().split()]
print(sorted([a * b, b * a])[-1])
Problem p02915 (python)

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

Buggy submission (verdict: Runtime Error):
return (int(input()) ** 3)
Problem p02951 (python)

Fixed submission:
a, b, c = [int(x) for x in input().split()]
print(c - min(c, a - b))

Buggy submission (verdict: Runtime Error):
given = int(input())
ans = 0
for i in range(given):
  current = str(i + 1)
  if len(current) & 1:
    ans += 1
  
print(ans)

Buggy submission (verdict: Runtime Error):
given = int(input())
ans = 0
for i in range(given):
  current = str(i + 1)
  ans += len(current) & 1
print(ans)
Problem p02552 (python)

Fixed submission:
x = int(input())
if x ==1:
  print(0)
else:
  print(1)

Buggy submission (verdict: Runtime Error):
 n = int(input())
  
print(1-n)
Problem p02578 (python)

Fixed submission:
n = int(input())
l = list(map(int,input().split()))
m = []
for i in range(n-1):
  if l[i]>l[i+1]:
     m.append(l[i]-l[i+1])
     l[i+1] = l[i]

print(sum(m))

Buggy submission (verdict: Runtime Error):
n = int(input())
l = list(map(int,input().split()))
m = []
for i in range(1,n+1):
  if l[i-1]>l[i]:
     m.append(l[i-1]-l[i])
      l[i] = l[i-1]

print(sum(m))

Buggy submission (verdict: Runtime Error):
n = int(input())
l = list(map(int,input().split()))
m = []
for i in range(1,n+1):
  if l[i-1]>l[i]:
     m.append(l[i-1]-l[i])
    l[i-1],l[i] = l[i],l[i-1]

print(sum(m))

Buggy submission (verdict: Runtime Error):
n = int(input())
l = list(map(int,input().split()))
m = []
for i in range(1,n+1):
  if l[i-1]>l[i]:
     m.append(l[i-1]-l[i])
    l[i] = l[i-1]

print(sum(m))

Buggy submission (verdict: Runtime Error):
n = int(input())
l = list(map(int,input().split()))
m = []
for i in range(n):
  if l[i]>l[i+1]:
     m.append(l[i]-l[i+1])
    l[i+1] = l[i]

print(sum(m))

Buggy submission (verdict: Runtime Error):
n = int(input())
l = list(map(int,input().split()))
ans = 0
for i in range(n):
  if l[i]>l[i+1]:
    ans = ans + l[i]-l[i+1]
    l[i+1] = l[i]

print(ans)
Problem p02594 (python)

Fixed submission:
X = input()
X = int(X)

if X >= 30:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
if X => 30:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
if X <30:
  print("No")
else:
  print("Yes")
Problem p02598 (python)

Fixed submission:
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,K=MI()
    A=LI()
    
    ng=0
    ok=10**9
    
    def f(x):
        temp=0#切る回数
        for i in range(N):
            temp+=(A[i]-0.1)//x
        
        return temp<=K
    
    while ok-ng>1:
        med=(ok+ng)//2
        if f(med):
            ok=med
        else:
            ng=med
               
    print(ok)
    

main()

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,K=MI()
    A=LI()
    
    ng=-1
    ok=10**9
    
    def f(x):
        temp=0
        for i in range(N):
            temp+=(A[i]-0.1)//x
        
        return temp<=K
    
    while ok-ng>1:
        med=(ok+ng)//2
        if f(med):
            ok=med
        else:
            ng=med
               
    print(ok)
    

main()
Problem p02707 (python)

Fixed submission:
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    A=LI()
    ans=[0]*N
     
     
    for i in range(N-1):
        ans[A[i]-1]+=1
        
    for i in range(N):
        print(ans[i])

main()

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    A=LI()
    ans=[0]*N
     
     
    for i in range(N):
        ans[A[i]-1]+=1
        
    for i in range(N):
        print(ans[i])

main()
Problem p02851 (python)

Fixed submission:
N, K = map(int,input().split())
A = list(map(int, input().split()))
S = [0]*(N+1)
S2 = [0]*(N+1)
dict = {}#最新K件の度数分布の管理

for i in range(N):
    S[i+1]=S[i]+A[i]
    S2[i+1] =(S[i+1]-i-1)%K

ans =0
for i in range(N+1):
    if dict.get(S2[i],0):
        ans += dict[S2[i]]
    dict[S2[i]]=dict.get(S2[i],0)+1
    if i >=K-1:
        dict[S2[i-(K-1)]]-=1

print(ans)

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))


"""
N^2なので素直に計算は無理，部分和を使いたいのでとりあえず累積和
[i+1:j]が条件を満たすとはS[j]-S[i]とj-iが合同．
移行して，S[j]-jとS[i]-iが合同
基本は個数だけ見れば良い

これだけだと，個数がKより大きい時にダメ
直近Kこの情報だけ持つ，今見てる数字が直近K個のものと何個組にできるか
"""
def main():

    mod=10**9+7
    N,K=MI()
    A=LI()
    from collections import defaultdict
    dd = defaultdict(int)
    
    S=[0]*(N+1)
    for i in range(N):
        S[i+1]=(S[i]+A[i])%K
        
    ans=0
    for i in range(K):
        temp=(S[i]-i)%K
        ans+=dd[temp]
        dd[temp]+=1
        
    for i in range(K,N+1):
        temp=(S[i]-i)%K
        temp_m=(S[(i-K)]-(i-K))%K
        dd[temp_m]-=1
        ans+=dd[temp]
        dd[temp]+=1
        
    print(ans)
        
        
    

        

main()
Problem p02859 (python)

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

Buggy submission (verdict: Runtime Error):
r = int(iinput())
print(r*r)
Problem p02862 (python)

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

a=(-x+2*y)//3
b=(2*x-y)//3
n=a+b

def fact(x,p):
    ret=1
    for i in range(1,x+1):
        ret*=i
        ret%=p
    return ret


if a+2*b==x and b+2*a==y and a>=0 and b>=0:
    ans=fact(n,mod) * pow(fact(b,mod),mod-2,mod)*pow(fact(a,mod),mod-2,mod)
    print(ans%mod)
else:
    print("0")

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    X,Y=MI()
    N3=X+Y
    
    if N3%3!=0:
        print(0)
        exit()
        
    N=N3//3
    a=0
    b=0
    for i in range(N3):
        if 2*i + (N-i) == X:
            a=i
            b=N-i
            break

    fact=[1,1]
    factinv=[1,1]
    inv=[0,1]

    for i in range(2, N + 1):
        fact.append((fact[-1] * i) % mod)
        inv.append((-inv[mod % i] * (mod // i)) % mod)
        factinv.append((factinv[-1] * inv[-1]) % mod)
        
    ans=fact[N]*factinv[a]*factinv[b]
    print(ans%mod)
    

main()
Problem p02873 (python)

Fixed submission:
#bfs

S=input()
N = len(S)+1

ans = 0
a = [None]*N

prev = ">"
q=[]

#確定0を埋める．
for i in range(N-1):
    if prev==">" and S[i] == "<":
        a[i]=0
        q.append(i)
    prev = S[i]

if S[-1]==">":
    a[-1]=0
    q.append(N-1)

while len(q)!=0:
    i = q.pop()
    if i+1 < N:
        if S[i]=="<":
            if a[i+1]==None:
                a[i+1]=a[i]+1
                q.append(i+1)
            else:
                a[i+1]=max(a[i]+1,a[i+1])
    if i-1>=0:
        if S[i-1]==">":
            if a[i-1]==None:
                a[i-1]=a[i]+1
                q.append(i-1)
            else:
                a[i-1]=max(a[i]+1,a[i-1])

print(sum(a))

Buggy submission (verdict: Runtime Error):
#bfs

S=input()
N = len(S)+1

ans = 0
a = [None]*N

prev = ">"
q=[]

#確定0を埋める．
for i in range(N-1):
    if prev==">" and S[i] == "<":
        a[i]=0
        q.append(i)
    prev = S[i]

if S[-1]==">":
    a[-1]=0
    q.append(N-1)

while len(q)!=0:
    i = q.pop()
    if i+1 < N:
        if S[i]=="<":
            if a[i+1]==None:
                a[i+1]=a[i]+1
                q.append(i+1)
            else:
                a[i+1]=max(a[i]+1,a[i+1])
    if i-1>0:
        if S[i-1]==">":
            if a[i-1]==None:
                a[i-1]=a[i]+1
                q.append(i-1)
            else:
                a[i-1]=max(a[i]+1,a[i-1])

print(sum(a))
Problem p03038 (python)

Fixed submission:
N,M=map(int,input().split())
A=list(map(int,input().split()))
CB=[[0,0] for _ in range(M)]

for i in range(M):
    CB[i][1],CB[i][0]=map(int,input().split())
    
A.sort()
CB.sort(reverse=True)

#Aを小さい順に見る，Cが大きい順に変更操作をして確定していく
cc=0
ans=0
for i in range(N):
    if cc<M:
        if A[i]<CB[cc][0]:
            A[i]=CB[cc][0]
            CB[cc][1]-=1
            if CB[cc][1]==0:
                cc+=1
    ans+=A[i]
        
print(ans)

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,M=MI()
    A=LI()
    B=[0]*N
    C=[0]*N
    for i in range(M):
        B[i],C[i]=MI()
    
    C,B=zip(*sorted(zip(C,B)))
    B=B[::-1]
    C=C[::-1]
    
    import heapq
    heapq.heapify(A)
    
    for i in range(M):
        b=B[i]
        c=C[i]
        for _ in range(b):
            a=heapq.heappop(A)
            if a>=c:
                heapq.heappush(A,a)
                break
            else:
                heapq.heappush(A,c)
                
    ans=0
    for i in range(N):
        a=heapq.heappop(A)
        ans+=a
        
    print(ans)

main()

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,M=MI()
    A=LI()
    CB=[[0,0]for _ in range(M)]
    A.sort()
    for i in range(M):
        CB[i][1],CB[i][0]=MI()
        
    CB.sort(reverse=True)
    now=0
    
    for i in range(N):
        if CB[now][1]<=0:
            now+=1
        ch=CB[now][0]
        if A[i]<ch:
            A[i]=ch
            CB[now][1]-=1
        else:
            break
        
    print(sum(A))
    

main()