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

Fixed submission:
N = input()

if N[0] == '7' or N[1] == '7' or N[2] == '7':
  print("Yes")
else:
  print("No")

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

ans = S.count('R') * S.count('G') * S.count('B')
for i in range(N):
  for j in range(i+1,N):
    if (i+j)%2 :
      continue
    k = (i+j)//2
    if len(set([S[i],S[k],S[j]])) == 3:
      ans -= 1
      
print(ans)
Problem p02753 (python)

Fixed submission:
s = input()
if s == "AAA" or s == "BBB":
  print("No")
else:
  print("Yes")

Buggy submission (verdict: Runtime Error):
cuts = []
for i in range(2000):
  cuts+= [[int(i*0.08), int(i*0.10)]]
  
A, B = map(int,input().split())

for i in range(1,2000):
  if [A, B] == cuts[i]:
    print(i)
    break
else:
  print(0)
Problem p02759 (python)

Fixed submission:
print(((int(input()))+1)//2)

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

N, M, K = map(int, input().split())
friends_table = [[] for i in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    friends_table[a-1] += [b-1]
    friends_table[b-1] += [a-1]

group_list = [i for i in range(N)]
friends_candidate = [[] for i in range(N)]

for i in range(N):
    # すでにDFS済み
    if i != group_list[i]:
        continue
    next_stack = [i]
    friend = [i]
    while next_stack:
        u = next_stack.pop(-1)
        for v in friends_table[u]:
            # 訪問済み
            if i == group_list[v]:
                continue
            friend += [v]
            group_list[v] = i
            next_stack += [v]
    for f in friend:
        friends_candidate[f] = friend

blocks_table = [[] for i in range(N)]
for _ in range(K):
    a, b = map(int, input().split())
    if group_list[a-1] == group_list[b-1]:
        blocks_table[a-1] += [b-1]
        blocks_table[b-1] += [a-1]

for i in range(N):
    print(len(friends_candidate[i]) - len(friends_table[i]) - len(blocks_table[i])-1)

Buggy submission (verdict: Runtime Error):
N, M, K = map(int, input().split())
friends_table = [[] for i in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    friends_table[a-1] += [b-1]
    friends_table[b-1] += [a-1]

blocks_table = [[] for i in range(N)]
for _ in range(K):
    a, b = map(int, input().split())
    blocks_table[a-1] += [b-1]
    blocks_table[b-1] += [a-1]

group_list = [i for i in range(N)]
friends_candidate = [[] for i in range(N)]

for i in range(N):
    friend = [i]
    # すでにDFS済み
    if i != group_list[i]:
        continue
    next_stack = friends_table[i][:]]
    while next_stack:
        next = next_stack.pop()
        # 訪問済み
        if i == group_list[next]:
            continue
        friend += [next]
        group_list[next] = i
        next_stack += friends_table[next]
    for f in friend:
        friends_candidate[f] = friend

for i in range(N):
    print(len(set(friends_candidate[i]).difference(set(friends_table[i] + blocks_table[i])))-1)

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

S, C = [], []
for i in range(M):
  s, c = map(int, input().split())
  S += [s-1]
  C += [str(c)]
  
if N == 1:
  for i in range(10):
    flag = 1
  for m in range(M):
      if i_str[S[m]] != C[m]:
        flag = 0
        break
    if flag:
      print(i)
      break
  else:
    print(-1) 
else:
  for i in range(10**(N-1), 10**N):
    flag = 1
    i_str = str(i)
    for m in range(M):
      if i_str[S[m]] != C[m]:
        flag = 0
        break
    if flag:
      print(i)
      break
  else:
    print(-1)

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

S, C = [], []
for i in range(M):
  s, c = map(int, input().split())
  S += [s-1]
  C += [str(c)]
  
for i in range(10**(N-1), 10**N):
  flag = 1
  i_str = str(i)
  for m in range(M):
    if i_str[S[m]] != C[m]:
      flag = 0
      break
  if flag:
    print(i)
    break
else:
  print(-1)
Problem p02777 (python)

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

dic = {S: A, T: B}
U = input()
dic[U] = dic[U]-1
print(dic[S], dic[T])

Buggy submission (verdict: Runtime Error):
N = int(input())
K = int(input())
L = len(str(N))

suu = []
for i in range(L):
    suu.append(int(str(N)[i]))

DP_1 =[[0 for k in range(L+1)] for i in range(L+1)]
DP_2 =[[0 for k in range(L+1)] for i in range(L+1)]
DP_2[0][0] = 1
for i in range(L):
    for k in range(L+1):
        DP_1[i+1][k] = DP_1[i][k] + DP_1[i][k-1] * 9 
        if suu[i]:
            DP_1[i+1][k] += DP_2[i][k] + DP_2[i][k-1] * max(suu[i] - 1, 0)
            DP_2[i+1][k] = DP_2[i][k-1]
        else:
            DP_2[i+1][k] = DP_2[i][k]
print(DP_1[L][K]+ DP_2[L][K])
Problem p02819 (python)

Fixed submission:
def check_prime(m):
  prime_flag = 1
  counter = 2
  while counter **2 <= m:
    if not m%counter:
      prime_flag = 0
      break
    counter += 1
  return prime_flag


n = int(input())

for i in range(n, 10**6):
  if check_prime(i):
    print(i)
    break

Buggy submission (verdict: Runtime Error):
def check_prime(m):
  prime_flag = 1
  counter = 1
  while counter **2 <= m:
    if not m%counter:
      prime_flag = 0
      break
  return prima_flag


n = int(input())

for i in range(n, 10**6):
  if check_prime(i):
    print(i)
    break
Problem p02829 (python)

Fixed submission:
a=int(input())
b=int(input())

ans=[1,2,3]
ans.remove(a)
ans.remove(b)
print(ans[0])

Buggy submission (verdict: Runtime Error):
a,b= map(int,input().split())
ans=[1,2,3]
ans.remove(a)
ans.remove(b)
print(ans[0])
Problem p02925 (python)

Fixed submission:

N = int(input())
A = [[x-1 for x in list(map(int, input().split()))[::-1]] for _ in range(N)]


def can_match(i, A, next_set):
  if not A[i]:
    return
  j = A[i][-1]
  if A[j][-1] == i:
    if i < j:
      next_set.add((i,j))
    else:
      next_set.add((j,i))

      
next_set = set()
for i in range(N):
  can_match(i, A, next_set)
  
day = 0
battle = 0
while next_set:
  day += 1
  current_set = next_set.copy()
  next_set = set()
  for match in current_set:
    battle += 1
    del A[match[0]][-1]
    can_match(match[0], A, next_set)
    del A[match[1]][-1]
    can_match(match[1], A, next_set)
if battle == N*(N-1)//2:
  print(day)
else:
  print(-1)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [[x-1 for x in list(map(int, input().split()))[::-1]] for _ in range(N)]

def can_match(i, A, next_set):
  if not A[i]:
    return
  if A[A[i][-1]][-1] == i:
    if i < j:
      next_set.add((i,j))
    else:
      next_set.add((j,i))
      
next_set = set()
for i in range(N):
  can_match(i, A, next_set)
  
day = 0
battle = 0
while next_set:
  day += 1
  current_set, next_set = next_set, set()
  for match in current_set:
    battle += 1
    del A[match[0]][-1]
    can_match(match[0], A, next_set)
    del A[match[1]][-1]
    can_match(match[1], A, next_set)
    
if battle == N*(N-1)//2:
  print(day)
else:
  print(-1)
Problem p02933 (python)

Fixed submission:
a = int(input())
if a >= 3200:
  print(input())
else:
  print("red")

Buggy submission (verdict: Runtime Error):
import sys
s = input()
t = input()
table = [[len(s) for i in range(len(s))] for j in range(26)]

for i in range(len(s)):
  table[ord(s[i])-97][i] = 0
for i in range(26):
  for j in range(len(s)):
    table[i][len(s)-j-2] = min(table[i][len(s)-j-1] +1, table[i][len(s)-j-2])
  for j in range(len(s)):
    table[i][len(s)-j-2] = min(table[i][len(s)-j-1] +1, table[i][len(s)-j-2])

for letter in t:
  if s.find(letter) == -1:
    print(-1)
    sys.exit()
    
place = 0
ans = 0
for i in range(len(t)):
  letter = t[i]
  move = table[ord(t[i])-97][place]
  ans += move + 1
  place = (place + move+1)%len(s)
print(ans)
Problem p03011 (python)

Fixed submission:
A = list(map(int, input().split()))
A.sort()
print(sum(A[:2]))

Buggy submission (verdict: Runtime Error):
A = list(map(int, input().split())).sort()
print(sum[:2])
Problem p03053 (python)

Fixed submission:
from collections import deque
H, W = map(int, input().split())
A = [input() for i in range(H)]

dx = [1,-1,0,0]

dy = [0,0,1,-1]
B = [[-1 for i in range(W)] for j in range(H)]
qu = deque([])
for i in range(H):
  for j in range(W):
    if A[i][j] == '#':
      B[i][j] = 0
      qu.append((i,j))
      
      
while qu:
  base = qu.popleft()
  for i in range(4):
    if base[0]+dx[i] < 0 or base[0]+dx[i] >=H or base[1]+dy[i] < 0 or base[1]+dy[i] >=W:
      continue
    if B[base[0]+dx[i]][base[1]+dy[i]] == -1:#未訪問
      qu.append((base[0]+dx[i],base[1]+dy[i]))
      B[base[0]+dx[i]][base[1]+dy[i]] = B[base[0]][base[1]] + 1
      
ans = 0
for i in range(H):
  ans = max(ans,max(B[i]))
print(ans)

Buggy submission (verdict: Runtime Error):
H, W, N = map(int, input().split())
sr, sc = map(int, input().split())
S = input()
T = input()

flag = 0
hidari = sc
migi = sc
ue = sr
shita = sr
for i in range(N):
  if S[i] == 'L':
    hidari -= 1
  if S[i] == 'R':
    migi += 1
  if S[i] == 'U':
    ue -= 1
  if S[i] == 'D':
    shita += 1
  if hidari == 0 or migi == W+1 or ue == 0 or shita == H+1 :
    flag = 1
  
  if T[i] == 'R' and hidari != W:
    hidari += 1
  if T[i] == 'L' and migi != 1:
    migi -= 1
  if T[i] == 'D' and ue != 1:
    ue += 1
  if T[i] == 'U' and shita != H:
    shita -= 1

if flag :
  print("NO")
else :
  print("YES")
Problem p03250 (python)

Fixed submission:
A = list(map(int, input().split()))
A.sort()
print(A[0]+A[1]+10*A[2])

Buggy submission (verdict: Runtime Error):
A = list(map(int, input().split()))
A.sort()
ans(A[0]+A[1]+10*A[2])
Problem p03327 (python)

Fixed submission:
N= int(input())
if N>999:
  print("ABD")
else:
  print("ABC")

Buggy submission (verdict: Runtime Error):
N, C = map(int, input().split())
D = [list(map(int, input().split())) for i in range(C)]
line1 = [0]*C
line2 = [0]*C
line0 = [0]*C
for i in range(N):
  c = list(map(int, input().split()))
  for j in range(N):
    if (i+j)%3 == 0:
      line0[c[j]-1] +=+1
    if (i+j)%3 == 1:
      line1[c[j]-1] +=+1
    if (i+j)%3 == 2:
      line2[c[j]-1] +=+1
ans = float("inf")
#line0をi+1に、1をj+1に, 2をk+1にそろえよう
#print(line0,line1,line2)
for i in range(C):
  for j in range(C):
    if j !=i :
      for k in range(C):
        if k !=i and k!=j: 
#          print(i,j,k)
          curr = 0
          for l in range(C):
            curr += line0[l]*D[l][i]
            curr += line1[l]*D[l][j]
            curr += line2[l]*D[l][k]
#          print(curr)
          ans = min(ans, curr)
print(ans)
Problem p03329 (python)

Fixed submission:
n = int(input())
possible = [1]
i=1
while i <= 100000:
  i = i*6
  possible+=[i]
i=1
while i <= 100000:
  i = i*9
  possible+=[i]
possible.sort(reverse =1)
ans = 0
table = set([n])
while True:
  if 0 in table:
    print(ans)
    break
  ans+=1
  nexttable = set()
  for num in table:
    for p in possible:
      if num - p >= 0:
        nexttable.add(num-p)
  table =nexttable

Buggy submission (verdict: Runtime Error):
n = int(input())
possible = [1]
i=1
while i <= 100000:
  i = i*6
  possible+=[i]
i=1
while i <= 100000:
  i = i*9
  possible+=[i]
possible.sort(reverse =1)
ans = 1
table = set(possible)
while True:
  if n in table:
    print(ans)
    break
  ans+=1
  nexttable = set()
  for num in table:
    for p in possible:
      if num + p <100000
        nexttable.add(num+p)
  table = table | nexttable
Problem p03634 (python)

Fixed submission:
from sys import stdin
input = stdin.readline
from collections import deque
def BFS(K,path,N):
  """リストのリスト道順path,頂点の個数Nが与えられたとき, 頂点Kから各頂点までの距離をlistで返す"""
  dist=[-1]*N
  dist[K]=0
  que=deque()
  que.append(K)
  while que:
    label=que.popleft()
    for i,c in path[label]:
      if dist[i]==-1:
        dist[i]=dist[label]+c
        que+=[i]
  return dist
 
N=int(input())
path=[ [] for i in range(N)]
for i in range(N-1):
  a,b,c=map(int,input().split())
  path[a-1]+=[[b-1,c]]
  path[b-1]+=[[a-1,c]]
Q,K=map(int,input().split())
xy=[list(map(int,input().split())) for i in range(Q)]
distance=BFS(K-1,path,N)
for i in range(Q):
  print(distance[xy[i][0]-1]+distance[xy[i][1]-1])

Buggy submission (verdict: Runtime Error):
def BFS(K,edges,N):
  roots=[ [] for i in range(N)]
  for a,b,c in edges:
    roots[a-1]+=[(b-1,c)]
    roots[b-1]+=[(a-1,c)]
  dist=[-1]*N
  stack=[]
  stack.append(K)
  dist[K]=0
  while stack:
    label=stack.pop(-1)
    for i,c in edges[label]:
      if dist[i]==-1:
        dist[i]=dist[label]+c
        stack+=[i]
  return dist
 
N=int(input())
edges=[]
for i in range(N-1):
  edges+=[list(map(int,input().split()))]
Q,K=map(int,input().split())
xy=[list(map(int,input().split())) for i in range(Q)]
distance=BFS(K-1,edges,N)
for i in range(Q):
  print(distance[xy[i][0]-1]+distance[xy[i][1]-1])
Problem p03705 (python)

Fixed submission:
N,A,B=map(int, input().split())
# 出力
if A>B:
  print(0)
elif N==1:
  if A==B:
    print(1)
  else:
    print(0)
else:
  M=A+B*(N-1)
  m=A*(N-1)+B
  print(M-m+1)

Buggy submission (verdict: Runtime Error):
A=int(input())
B=int(input())
S=[]
times=len(format(A^B,"b"))
for i in range(A,B+1):
  S+=[i]
D=S[:] #Dは基礎集合
SET=set(S)
#for t in range(times):
for i in range(len(S)):
  for j in range(len(D)):
    S+=[S[i]|D[j]]
    SET.add(S[i]|D[j])
print(len(SET))
Problem p03723 (python)

Fixed submission:
# -*- coding: utf-8 -*-
import sys
# 整数の入力
A, B, C= map(int, input().split())
# 出力
if A==B and B==C:
 if A%2 ==0 and B%2==0 and C%2==0:
  print(-1)
  sys.exit()
count=0
while True:
 if A%2 ==1 or B%2==1 or C%2==1:
  print(count)
  sys.exit()
 else:
  A_a=B/2+C/2
  B_a=A/2+C/2
  C_a=A/2+B/2
  A=A_a
  B=B_a
  C=C_a
  count+=1

Buggy submission (verdict: Runtime Error):
import sys
# 整数の入力
N,M=list(map(int, input().split()))
p=[]
q=0
count=0
for i in range(0,M):
  p.append(list(map(int, input().split())))
for i in range(0,M):
  q+=p[i][0]-p[i][1]
if q%2==1:
  print("NO")
else:
  m=int(M/100)
  for j in range(0,M,m):
    for i in range(0,M):
      if p[i][0]==j or p[i][1]==j:
        count+=1
    if count%2==1:
      print("NO")
      sys.exit()
  else: 
    print("YES")
Problem p03776 (python)

Fixed submission:
import math

N,A,B=map(int, input().split())
v=list(map(int, input().split()))

v.sort()
v.reverse()
w=0
for i in range (0,A):
  w+=v[i]
ave=w/A
print(ave)

mini=v[A]
C=v[0:A].count(mini)#最低個数
D=v[0:A].count(mini)+B-A#要素が増えても平均が落ちない場合の最大個数
if v[0]!=v[A]:#要素が増えたら平均が落ちる場合
  D=A
  for k in range (0,A):
    if v[k]>v[A]:
      D-=1#最大個数はB-(v[A]より大きいものの個数)
p=v.count(mini)#最小の人たちの個数
D=min(D,p)

q=0
for k in range (C,D+1):
  q+=math.factorial(p)/(math.factorial(p-k)*math.factorial(k))
print(int(q))

Buggy submission (verdict: Runtime Error):
import math

N,A,B=map(int, input().split())
v=list(map(int, input().split()))

v.sort()
v.reverse()
w=0
for i in range (0,A):
  w+=v[i]
ave=w/A
print(ave)

min=v[A]


C=v[0:A].count(min)#最低個数
D=v[0:A].count(min)+B-A#要素が増えても平均が落ちない場合の最大個数
if v[0]!=v[A]:#要素が増えたら平均が落ちる場合
  D=A
  for k in range (0,A):
    if v[k]>v[A]:
      D-=1#最大個数はB-(v[A]より大きいものの個数)
p=v.count(min)#最小の人たちの個数
q=0
for k in range (C,D+1):
  q+=math.factorial(p)/(math.factorial(p-k)*math.factorial(k))
print(int(q))
Problem p03803 (python)

Fixed submission:
A,B=map(int, input().split())
if (A+12)%14 > (B+12)%14:
  print("Alice")
elif A==B:
  print("Draw")
else:
  print("Bob")

Buggy submission (verdict: Runtime Error):
import sys
N,M=map(int,input().split())
A=[]
B=[]
A+=[str(input()) for i in range(N)]
B+=[str(input()) for i in range(M)]
for i in range(N-M+1):
  for j in range(N-M+1):
    ans=1
    for k in range(M):
      for l in range(M):
        if B[k][l]!=A[i+k][j+l]:
          ans=0
    if ans:
      print("Yes")
      sys.exit()
print("No")
Problem p02571 (python)

Fixed submission:
S = input()
T = input()
ans = 1001
for i in range(len(S) - len(T) + 1):
  a = 0
  for s in range(len(T)):
    if T[s] != S[i+s]:
      a += 1
  if a < ans:
    ans = a
print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
T = input()
t = len(T)
for i in range(len(T)):
  a = 0
  b = 0
  for s in range(len(T)):
    if T[s:s+i+1] in S[s:len(S)-s]:
      b += 1
    print(s,b,T[s:s+i+1],S[s:len(S)-s])
  if b == 0:
    break
print(t-i)
Problem p02622 (python)

Fixed submission:
S = input()
T = input()
ans = 0
for i in range(len(S)):
  if S[i] == T[i]:
    continue
  ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
T = input()
ans = 0
for i in range(S):
  if S[i+1] == T[i+1]:
    ans += 1
print(ans)
Problem p02549 (python)

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

mod = 998244353

dp = [0] * n
dp[0] = 1
sum_dp = [0, 1]
for i in range(1, n):
    for l, r in sec:
        if i - l < 0:
            break
        elif i - r > 0:
            dp[i] = ((dp[i] + sum_dp[i-l+1]) % mod - sum_dp[i-r]) % mod
        else:
            dp[i] = (dp[i] + sum_dp[i-l+1]) % mod
    
    sum_dp.append((sum_dp[-1] + dp[i]) % mod)

print(dp[n-1])

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

mod = 998244353

dp = [0] * n
dp[0] = 1
sum_dp = [0, 1]
for i in range(1, n):
    for l, r in sec:
        if i - l < 0:
            break
        elif i - r > 0:
            dp[i] = ((dp[i] + sum_dp[i-l+1]) % mod - sum_dp[i-r]) % mod
        else:
            dp[i] = (dp[i] + sum_dp[i-l+1]) % mod
    
    sum_dp.append((sum_dp[-1] + dp[i]) % modp)

print(dp[n-1])
Problem p02598 (python)

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

hi = 10 ** 9
lo = 0
while hi - lo > 1:
    mid = (hi + lo) // 2

    cnt = 0
    for v in a:
        cnt += (v + mid - 1) // mid - 1

    if cnt <= k:
        hi = mid
    else:
        lo = mid

print(hi)

Buggy submission (verdict: Runtime Error):
# Binary Search

def isOK(i, key):
    '''
    問題に応じて返り値を設定
    '''
    cnt = 0
    for v in a:
        cnt += (v + i - 1) // i - 1

    return cnt <= key


def binary_search(key):
    '''
    条件を満たす最小/最大のindexを求める
    O(logN)
    '''
    ok = 10 ** 9  # 条件を満たすindexの上限値/下限値
    ng = -1       # 条件を満たさないindexの下限値-1/上限値+1
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2

        if isOK(mid, key):  # midが条件を満たすか否か
            ok = mid
        else:
            ng = mid
    
    return ok


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

Buggy submission (verdict: Runtime Error):
def binary_search(key):
    '''
    条件を満たす最小/最大のindexを求める
    '''
    ok = 10 ** 9 + 1  # 条件を満たすindexの上限値/下限値
    ng = -1           # 条件を満たさないindexの下限値/上限値
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2

        cnt = 0
        for v in a:
            cnt += (v + mid - 1) // mid - 1

        if cnt <= key:  # midが条件を満たすか否か
            ok = mid
        else:
            ng = mid
    
    return ok


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

print(binary_search(k))

Buggy submission (verdict: Runtime Error):
def binary_search(key):
    '''
    条件を満たす最小/最大のindexを求める
    '''
    ok = 10 ** 9 + 1  # 条件を満たすindexの上限値/下限値
    ng = -1           # 条件を満たさないindexの下限値/上限値
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2

        if isOK(mid, key):  # midが条件を満たすか否か
            ok = mid
        else:
            ng = mid
    
    return ok


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

print(binary_search(k))
Problem p02659 (python)

Fixed submission:
a, b = input().split()
print(int(a) * round(float(b) * 100) // 100)

Buggy submission (verdict: Runtime Error):
a, b = input().split()
a, b_100 = int(a), int(b.replace('.', ''))
print(a * b // 100)
Problem p02757 (python)

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

if p == 2:
    s = input()
    ans = 0
    for i in range(n):
        if int(s[i]) % 2 == 0:
            ans += i + 1
    print(ans)

elif p == 5:
    s = input()
    ans = 0
    for i in range(n):
        if int(s[i]) % 5 == 0:
            ans += i + 1
    print(ans)

else:
    s = input()[::-1]
    mod = 0
    c = [0] * p
    c[0] = 1
    ten = 1
    for i in s:
        mod = (mod + ten * int(i)) % p
        ten = ten * 10 % p
        c[mod] += 1

    ans = 0
    for i in c:
        ans += i * (i - 1) // 2
    print(ans)

Buggy submission (verdict: Runtime Error):
n, p = map(int, input().split())
s = input()[::-1]
ans = 0

if p == 2:
    for i in range(n):
        if s[i] % 2 == 0:
            ans += i + 1
    print(ans)

elif p == 5:
    for i in range(n):
        if s[i] % 5 == 0:
            ans += i + 1
    print(ans)

else:
    mod = 0
    c = [0] * p
    c[0] = 1
    ten = 1
    for i in s:
        mod = (mod + ten * int(i)) % p
        ten = ten * 10 % p
        c[mod] += 1

    for i in c:
        ans += i * (i - 1) // 2
    print(ans)
Problem p02793 (python)

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

    if n != 1:
        e[n] = max(e[n], 1)


def mod_pow(a, n):
    res = 1
    while n > 0:
        if n & 1:
            res = res * a % mod
        a = a * a % mod
        n >>= 1
    return res


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

mod = 10 ** 9 + 7
e = [0] * 10 ** 6

for v in a:
    factorization(v)

lcm = 1
for i, c in enumerate(e):
    if c > 0:
        lcm = lcm * mod_pow(i, c) % mod

res = 0
for v in a:
    res = (res + lcm * mod_pow(v, mod - 2)) % mod

print(res)

Buggy submission (verdict: Runtime Error):
from math import gcd

def factorization(n):
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            cnt = 0
            while n % i == 0:
                cnt += 1
                n //= i
            e[i] = max(e[i], cnt)

    if n != 1:
        e[n] = max(e[n], 1)


def mod_pow(a, n):
    res = 1
    while n > 0:
        if n & 1:
            res = res * a % mod
        a = a * a % mod
        n >>= 1
    return res


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

mod = 10 ** 9 + 7
e = [0] * 10 ** 6

for v in a:
    factorization(v)

lcm = 1
for i, c in enumerate(e):
    if c > 0:
        lcm = lcm * mod_pow(i, c) % mod

res = 0
for v in a:
    res = (res + lcm * mod_pow(v, mod - 2)) % mod

print(res)
Problem p02862 (python)

Fixed submission:
fac = [0] * 700000
finv = [0] * 700000
inv = [0] * 700000
mod = 1000000007

fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1
for i in range(2, 700000):
    fac[i] = fac[i - 1] * i % mod
    inv[i] = mod - inv[mod % i] * (mod // i) % mod
    finv[i] = finv[i - 1] * inv[i] % mod

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

if (x + y) % 3 == 0:
    k = (2 * x - y) // 3
    l = (2 * y - x) // 3
    if k >= 0 and l >= 0:
        print(fac[k + l] * (finv[k] * finv[l] % mod) % mod)
    else:
        print(0)
else:
    print(0)

Buggy submission (verdict: Runtime Error):
import sys
import math

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

if (2 * x - y) % 3 != 0 or (2 * y - x) % 3 != 0:
    print(0)
    sys.exit()

k = (2 * x - y) // 3
l = (2 * y - x) // 3

ans = math.factorial(k + l) // (math.factorial(k) * math.factorial(l))

print(ans % (10 ** 9 + 7))
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] + a[i + 1] < b[i]:
        ans += a[i] + a[i + 1]
        a[i + 1] = 0
    else:
        ans += b[i]
        if a[i] < b[i]:
            a[i + 1] -= b[i] - a[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] + a[i + 1] < b[i]:
        ans += a[i] + a[i + 1]
        a[i + 1] = 0
    else:
        ans += b[i]
        if a[i] < b[i]:
            a[i + 1] -= b[i] - a[i]

print(ans)