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

Fixed submission:
import numpy as np
#from numba import njit

#(N, K) = map(int, input().split())
#A = np.array(list(map(int, input().split())))
(N,M) = map(int, input().split())
X = map(int, input().split())
X = sorted(X)

Y = []
for i in range(1,M):
    Y.append((i,X[i] - X[i-1]))

Y = sorted(Y, key=lambda x: (x[1]))
Y.reverse()

I = list(map(lambda x: x[0], Y[0:min(N-1, len(Y))]))
I.sort()

Z = []
last = 0
for i in range(0,min(N-1, len(Y))):
    if last < I[i]:
        Z.append(X[last:I[i]])
        last = I[i]
Z.append(X[last:])
if len(Z) == 0:
    Z.append(X)

s = 0
for array in Z:
    if len(array) > 0:
        u = max(array)
        l = min(array)
        s += u - l

print(s)

Buggy submission (verdict: Runtime Error):
import numpy as np
#from numba import njit

#(N, K) = map(int, input().split())
#A = np.array(list(map(int, input().split())))
(N,M) = map(int, input().split())
X = map(int, input().split())
X = sorted(X)

Y = []
for i in range(1,M):
    Y.append((i,X[i] - X[i-1]))

Y = sorted(Y, key=lambda x: (x[1]))
Y.reverse()

Z = []
last = 0
for i in range(0,min(N-1, len(Y))):
    Z.append(X[last:Y[i][0]])
    last = Y[i][0]
Z.append(X[last:])
if len(Z) == 0:
    Z.append(X)

s = 0
for array in Z:
    u = max(array)
    l = min(array)
    s += u - l

print(s)

Buggy submission (verdict: Runtime Error):
import numpy as np
#from numba import njit

#(N, K) = map(int, input().split())
#A = np.array(list(map(int, input().split())))
(N,M) = map(int, input().split())
X = map(int, input().split())
X = sorted(X)

Y = []
for i in range(1,M):
    Y.append((i,X[i] - X[i-1]))

Y = sorted(Y, key=lambda x: (x[1]))
Y.reverse()

Z = []
last = 0
for i in range(0,min(N-1, len(Y))):
    Z.append(X[last:Y[i][0]])
    last = Y[i][0]
if len(Z) == 0:
    Z.append(X)

s = 0
for array in Z:
    u = max(array)
    l = min(array)
    s += u - l

print(s)
Problem p02623 (python)

Fixed submission:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(N):
	a.append(a[i] + A[i])
for i in range(M):
	b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N + 1):
	if a[i] > K:
		break
	while b[j] > K - a[i]:
		j -= 1
	ans = max(ans, i + j)
print(ans)

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

a, b = [0], [0]
for i in range(N):
	a.append(a[i] + A[i])
for i in range(M):
	b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N + 1):
	a[i] > K:
		break
	while b[j] > K - a[i]:
		j -= 1
	ans = max(ans, i + j)
print(ans)

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

a, b = [0], [0]
for i in range(N):
a.append(a[i] + A[i])
for i in range(M):
b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N + 1):
a[i] > K:
break
while b[j] > K - a[i]:
j -= 1
ans = max(ans, i + j)
print(ans)
Problem p02723 (python)

Fixed submission:
# inputs = list(map(int, (input().split())))

s = input()
if s[2] == s[3] and s[4] == s[5]:
    print("Yes")
else:
    print("No")

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

n = inputs[0]
x = inputs[1] - 1  # 3
y = inputs[2] - 1  # 7
z = y - x - 1  # 3
c = y - x + 1
k = [0 for i in range(n-1)]

for i in range(n - 1):
    for j in range(i + 1, n):
        if i <= x and j >= y:
            d = j - i - z
        elif i <= x and not j >= y:
            d = min(j - i, c - j + x + x - i)
        elif not i <= x and j >= y:
            d = min(j - i, c - y + i + j - y)
        else:
            d = j - i
        # print(str(i+1) + " "+str(j+1)+" "+str(d))
        k[d - 1] += 1

for e in k:
    print(e)
Problem p02689 (python)

Fixed submission:
N, M = map(int, input().split())
tenbo_height = list(map(int, input().split()))
adj_height = [0]*N

for i in range(M):
  #road[0] = start, road[1] = goal
  road = list(map(int, input().split()))
  adj_height[road[0]-1] = max(adj_height[road[0]-1], tenbo_height[road[1]-1])
  adj_height[road[1]-1] = max(adj_height[road[1]-1], tenbo_height[road[0]-1])
  
good_tenbo = 0
for tenbo in range(N):
  if ((tenbo_height[tenbo] > adj_height[tenbo])) or (adj_height[tenbo] == 0):
    good_tenbo += 1
print(good_tenbo)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
tenbo_height = list(map(int, input().split()))
roads = []
for i in range(M):
  #road[0] = start, road[1] = goal
  road = list(map(int, input().split()))
  roads.append(road)

good_tenbo = 0
for tenbo in range(N):
  adjacent_tenbo = []
  #good tenbo if no road or adjacent tenbo is all lower
  #count number of road connected to this tenbo
  for road in roads:
    if (road[0] == tenbo):
      adjacent_tenbo.append(road[1])
    elif (road[1] == tenbo):
      adjacent_tenbo.append(road[0])
  
  #check if no road connected
  if (len(adjacent_tenbo) == 0):
    good_tenbo += 1
    continue
  #check if adjacent tenbo is all lower
  all_lower = True
  for a_tenbo in adjacent_tenbo:
    if (tenbo_height[a_tenbo] >= tenbo_height[tenbo]):
      all_lower = False
      break
  if (all_lower):
    good_tenbo += 1
    continue
    
print(good_tenbo)
Problem p02723 (python)

Fixed submission:
s = input()
if s[2] == s[3] and s[4] == s[5]:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
s = input()
if s[2] == 2[3] and s[4] == s[5]:
  print("Yes")
else:
  print("No")
Problem p02729 (python)

Fixed submission:
import math
n, m = input().split()
m = int(m)
n = int(n)
if n == 1 or n == 0:
	nNum = 0
else:
	nNum = math.factorial(n) / (math.factorial(n-2) * math.factorial(2))
if m == 1 or m == 0:
	mNum = 0
else:
	mNum = math.factorial(m) / (math.factorial(m-2) * math.factorial(2))
print(int(mNum + nNum))

Buggy submission (verdict: Runtime Error):
import math
n, m = input().split()
m = int(m)
n = int(n)
if n == 1 or n == 0:
	nNum = 0
else:
	nNum = math.factorial(n) / (math.factorial(n-2) * math.factorial(2))
if m == 1 or n == 0:
	mNum = 0
else:
	mNum = math.factorial(m) / (math.factorial(m-2) * math.factorial(2))
print(int(mNum + nNum))

Buggy submission (verdict: Runtime Error):
import math
n, m = input().split()
m = int(m)
n = int(n)
if n == 1 or n == 0:
	nNum = 0
else:
	nNum = math.factorial(n) / (math.factorial(n-2) * math.factorial(2))
if m == 1 or n == 0:
	mNum = 0
else:
	mNum = math.factorial(m) / (math.factorial(m-2) * math.factorial(2))
print(int(mNum + nNum))

Buggy submission (verdict: Runtime Error):
import math
n, m = input().split()
m = int(m)
n = int(n)
if n == 1 or 0:
	nNum = 0
else:
	nNum = math.factorial(n) / (math.factorial(n-2) * math.factorial(2))
if m == 1 or 0:
	mNum = 0
else:
	mNum = math.factorial(m) / (math.factorial(m-2) * math.factorial(2))
print(int(mNum + nNum))

Buggy submission (verdict: Runtime Error):
import math
n, m = input().split()
m = int(m)
n = int(n)
if n == 1:
	nNum = 0
else:
	nNum = math.factorial(n) / (math.factorial(n-2) * math.factorial(2))
if m == 1:
	mNum = 0
else:
	mNum = math.factorial(m) / (math.factorial(m-2) * math.factorial(2))
print(int(mNum + nNum))

Buggy submission (verdict: Runtime Error):
import math
n, m = input().split()
m = int(m)
n = int(n)
mNum = math.factorial(n) / (math.factorial(n-2) * math.factorial(2))
nNum = math.factorial(m) / (math.factorial(m-2) * math.factorial(2))
print(int(mNum + nNum))
Problem p02753 (python)

Fixed submission:
buses = input()
first = buses[0]
count = 0
for i in buses:
	if (i == first):
    	   count += 1
if count == len(buses):
	print("No")
else:
	print("Yes")

Buggy submission (verdict: Runtime Error):
buses = input()
first = buses[0]
count = 0
for i in buses:
	if i == first:
      count += 1
if count == len(buses):
  print("No")
else:
  print("Yes")
Problem p02777 (python)

Fixed submission:
S, T = input().split()
A, B = map(int, input().split())
U = input()
if (U == T):
  print(str(A)+" "+str(B-1))
else:
  print(str(A-1)+" "+str(B))

Buggy submission (verdict: Runtime Error):
S, T = map(int, input().split())
A, B = map(int, input().split())
U = int(input())
if (U == T):
  print(str(A)+" "+str(B-1))
else:
  print(str(A-1)+" "+str(B))
Problem p02912 (python)

Fixed submission:
import heapq
N, M = map(int, input().split())

A = list(map(int, input().split()))
h = []

for i in range(N):
    A[i] *= -1

for i in range(N):
    heapq.heappush(h, A[i])

for i in range(M):
    num = heapq.heappop(h)
    num = num * -1
    num = num // 2
    heapq.heappush(h, -num)

print(-sum(h))

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

A = list(map(int, input().split()))
def soujyuu(left, right, num):
    if right - left <= 1:
        A.insert(right, num)
    else:
        if num >= A[left + right // 2]:
            left = left + right // 2
        else:
            right = left + right // 2
        soujyuu(left, right, num)


A.sort()
for i in range(M):
    maxA = A.pop(N-1)
    maxA = maxA // 2
    soujyuu(0,N-2, maxA)
    #print(A)

print(sum(A))

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

A = list(map(int, input().split()))
def soujyuu(left, right, num):
    if right - left <= 1:
        A.insert(right, num)
    else:
        if num >= A[left + right // 2]:
            left = left + right // 2
        else:
            right = left + right // 2
        soujyuu(left, right, num)


A.sort()
for i in range(M):
    maxA = A.pop(N-1)
    maxA = maxA // 2
    soujyuu(0,N-2, maxA)
    #print(A)

print(sum(A))
Problem p03011 (python)

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

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = [0 for i in range(N + 2)]
A[0] = 0
A[1] = 1
for i in range(M):
    a = int(input()) + 1
    A[a] = -1
for i in range(2, N+2):
    if A[i] ==  -1:
        A[i] = 0
    else:
        A[i] = A[i-1]+ A[i-2]
        A[i] = A[i] % 1000000007
    #print(A)
print(A[N + 1])

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
bre = []
flag = 0
A = []
for i in range(M):
    bre.append(int(input()))
#print(bre)
A.append(bre[0] - 1)
count = 0
if len(bre) >= 2:
    for i in range(len(bre) - 1):
        a = bre[i + 1] - bre[i]
        A.append(a - 2)
        if a == 1:
            #print(0)
            flag = 1
A.append(N - bre[len(bre) - 1] - 1)

if flag == 0:
    suu = [0, 1, 2]
    for i in range(2, max(A)+1):
        suu.append(suu[i] + suu[i-1] )
    #print(suu)
    for i in A:
        if count == 0:
            count = suu[i]
        else :
            count *= suu[i]
            count = count % 1000000007
    print(count)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
bre = []
flag = 0
A = []
for i in range(M):
    bre.append(int(input()))
#print(bre)
A.append(bre[0] - 1)
count = 0
if len(bre) >= 2:
    for i in range(len(bre) - 1):
        a = bre[i + 1] - bre[i]
        A.append(a - 2)
        if a == 1:
            #print(0)
            flag = 1
A.append(N - bre[len(bre) - 1] - 1)

if flag == 0:
    suu = [0, 1, 2]
    for i in range(2, max(A)):
        suu.append(suu[i] + suu[i-1] )
    #print(suu)
    for i in A:
        if count == 0:
            count = suu[i]
        else :
            count *= suu[i]
            count = count % 1000000007
    print(count % 1000000007)
Problem p02707 (python)

Fixed submission:
N = int(input())
array = list(map(int, input().strip().split()))
array.sort()
ansarray = []
ansnum = 1
ans = 0
ansindex = 0
for i in range (1,N):
    for j in range(ansindex,N-1):
        if (array[j] == i):
            ans += 1
            ansindex += 1
        else:
            ansarray.append(ans)
            ans = 0
            break
        if(j == N-2):
            ansarray.append(ans)
            ansindex += 1
for i in range(N-len(ansarray)):
    ansarray.append("0")
for i in range(N):
    print(ansarray[i])

Buggy submission (verdict: Runtime Error):
N = int(input())
array = list(map(int, input().strip().split()))
array.sort
ansarray = []
ansnum = 1
ans = 0
ansindex = 0
for i in range (1,N+1):
    for j in range(ansindex,N-1):
        if (array[j] == i):
            ans += 1
            ansindex += 1
        else:
            ansarray.append(ans)
            ans = 0
            break
        if(j == N-2):
            ansarray.append(ans)
for i in range(N-ansindex):
    ansarray.append("0")
for i in range(N):
    print(ansarray[i])
Problem p03265 (python)

Fixed submission:
def joinWithSpace(list):
    return " ".join([str(s) for s in list])


x1, y1, x2, y2 = [int(s) for s in input().split(" ")]

x3 = x2 - (y2-y1)
y3 = y2 + (x2-x1)
x4 = x1 - (y2-y1)
y4 = y1 + (x2-x1)

print(joinWithSpace([x3, y3, x4, y4]))

Buggy submission (verdict: Runtime Error):
x1, y1, x2, y2 = [int(s) for s in input().split(" ")]

x3 = x2 - (y2-y1)
y3 = y2 + (x2-x1)
x4 = x1 - (y2-y1)
y4 = y1 + (x2-x1)

print(f"{x3} {y3} {x4} {y4}")
Problem p02990 (python)

Fixed submission:
import math

N, K = list(map(int, input().split()))
mod = 10**9+7


def combination(a, b):
    ans = (math.factorial(a) // math.factorial(a-b)) // math.factorial(b)
    return ans


for i in range(1, K+1):
    if (N-K+1-i) >= 0:
        ans1 = combination(N-K+1, i)
        ans2 = combination(K-1, i-1)
        print(ans1 % mod*ans2 % mod)
    else:
        print(0)

Buggy submission (verdict: Runtime Error):
import math

N, K = map(int, input().split())


def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


w = 10**9+7
for i in range(1, K+1):
    if N-K+1-i > 0:
        ans1 = combinations_count(N-K+1, i)
        ans2 = combinations_count(K-1, i-1)
        ans = ans1 % w * ans2 % w
        print(ans)
        cnt += ans
    else:
        print(combinations_count(N, K) % w-cnt)

Buggy submission (verdict: Runtime Error):
import math

N, K = list(map(int, input().split()))
mod = 10**9+7


def combination(a, b):
    kekka = (math.factorial(a) // math.factorial(a-b)) // math.factorial(b)
    return kekka


for i in range(1, K+1):
    ans1 = combination(N-K+1, i)
    ans2 = combination(K-1, i-1)
    if (N-K+1-i) >= 0:
        print(ans1*ans2 % mod)

Buggy submission (verdict: Runtime Error):
import math

N, K = list(map(int, input().split()))
mod = 10**9+7


def combination(a, b):
    ans = (math.factorial(a) // math.factorial(a-b)) // math.factorial(b)
    return ans


for i in range(1, K+1):
    ans1 = combination(N-K+1, i)
    ans2 = combination(K-1, i-1)
    print(ans1*ans2 % mod)

Buggy submission (verdict: Runtime Error):
import math

N, K = list(map(int, input().split()))

red = N-K + 1

#print(N, K, red)
cnt = 0
for i in range(1,K):
    ans = math.factorial(red) // (math.factorial(red - i) * math.factorial(i))*i
    w = 10**9+7
    print(ans%w)
    cnt+=ans

All =  math.factorial(N) // (math.factorial(N-K) * math.factorial(K))%(10**9+7)
print(All-cnt)

Buggy submission (verdict: Runtime Error):
import math

N, K = list(map(int, input().split()))

red = N-K + 1

#print(N, K, red)
cnt = 0
for i in range(1,K):
    ans = math.factorial(red) // (math.factorial(red - i) * math.factorial(i))*i
    w = 10**9+7
    print(ans%w)
    cnt+=ans

All =  math.factorial(N) // (math.factorial(N-K) * math.factorial(K))%(10**9+7)
print(All-cnt)
Problem p02699 (python)

Fixed submission:
S,W= map(int,input().split())

if W>=S:
    print("unsafe")
else:
    print("safe")

Buggy submission (verdict: Runtime Error):
s=list(input())
from itertools import product, permutations,combinations


#l = len(s) +1
#A = [i for i in range(len(s)+1)]

cnt = 0
ans = []

for i in combinations([i for i in range(len(s)+1)],2):
    
    ans = s[i[0]:i[1]]
    if int("".join(map(str, ans)))%2019==0:
            cnt +=1
    
        
print(cnt)

Buggy submission (verdict: Runtime Error):
A,B,C,D = map(int,input().split())
#print(A,B,C,D)
def judge(A,B,C,D):
    while(True):
        C = C-B
        A = A - D
        if C<=0:
            return 1
            break
        elif A<=0:
            return 0
            break
if judge(A,B,C,D)==1:
    print("Yes")
else:
    print("No")
Problem p02723 (python)

Fixed submission:
cf =list(input())

if cf[2]==cf[3] and cf[4]==cf[5]:
    print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
cf =list(input())

if cf[2]=cf[3] and cf[4]=cf[5]:
    print("Yes")
else:
  print("No")
Problem p02773 (python)

Fixed submission:
N=int(input())
l={}
ans =[]
 
"""for i in range(N):
  s=input()
  if s in l:
    l[s]+=1
  else:
    l[s]=1
print(l)"""
for i in range(N):
    s=input()
    if s in l:
        l[s]+=1
    else:
        l[s]=1
#print(l)
num = max(l.values())
#print(max)
for i in l:
    #print(l[i])
    if l[i]==num:
      ans.append(i)
b = sorted(ans)
for i in b:
    print(i)

Buggy submission (verdict: Runtime Error):
N=int(input())
l={}
ans =[]
 
"""for i in range(N):
  s=input()
  if s in l:
    l[s]+=1
  else:
    l[s]=1
print(l)"""
for i in range(N):
    s=input()
    if s in l:
        l[s]+=1
    else:
        l[s]=1
#print(l)
max = max(l.values())
print(max)
for i in l:
    #print(l[i])
    if l[i]==num:
      ans.append(i)
b = sorted(ans)
for i in b:
    print(i)
Problem p02777 (python)

Fixed submission:
# coding: utf-8
# Your code here!
#########行列読み込み ##############################################
"""
from sys import stdin
n = int(stdin.readline().rstrip())
data = [stdin.readline().rstrip().split() for _ in range(n)]
print(data)
print(*data, sep='\n')
"""
##################################################################
#########入力系####################################################
"""
s =input()
s=list(input())
a=int(input())
x,y = map(int,input().split())	
li = input().split()	
li = list(map(int,input().split()))	
li = input().split('T')	
"""
##################################################################
li = input().split()
#print(li)
x,y = map(int,input().split())	
s =input()
if s==li[0]:
    print(x-1,y)
else:
    print(x,y-1)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
#########行列読み込み ##############################################
"""
from sys import stdin
n = int(stdin.readline().rstrip())
data = [stdin.readline().rstrip().split() for _ in range(n)]
print(data)
print(*data, sep='\n')
"""
##################################################################
#########入力系####################################################
"""
s =input()
s=list(input())
a=int(input())
x,y = map(int,input().split())	
li = input().split()	
li = list(map(int,input().split()))	
li = input().split('T')	
"""
##################################################################
import numpy as np
l ={}
N,K = map(int,input().split())
#P = list(map(int,input().split()))
P = np.asarray(list(map(int,input().split())))
#print(P)
P_ = []
#print(P_)

def kitai(num):
    x = 0
    for j in range(num):
        x += num-j
    return x/num
for i in P:
    P_.append(kitai(i))
#print(type(P_))


#print(P)
for i in range(0,N-K+1):
    #print(P[i:i+K])
    l[sum(P_[i:i+K])]=i
#print(l)
max = max(l.keys())
print(max)
import sys
def input():
    return sys.stdin.readline()[:-1]
Problem p02879 (python)

Fixed submission:
# coding: utf-8
# Your code here!

A , B = map(int,input().split())

if A >=10 or B >=10:
    print("-1")
else:
    print(A*B)

Buggy submission (verdict: Runtime Error):
A = int(input())
B = int(input())

if A >=10 or B >=10:
    print("-1")
else:
    print(A*B)
Problem p02623 (python)

Fixed submission:
n,m,k=map(int,input().split())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
ca=[0]*(n+1)
ca[1]=a[0]
for i in range(n):
  ca[i+1]=ca[i]+a[i]
cb=[0]*(m+1)
cb[1]=b[0]
for i in range(m):
  cb[i+1]=cb[i]+b[i]
j=m
ans=0
for i in range(n+1):
  t=ca[i]
  while j>=0:
    if t+cb[j]>k:
      j-=1
    else:
      ans=max(ans,i+j)
      break
print(ans)

Buggy submission (verdict: Runtime Error):
n,m,k=map(int,input().split())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
a.reverse()
b.reverse()
ans=0
t=0
while len(a)>0 or len(b)>0:
  if len(a)>0 and a[-1]<b[-1]:
    t+=a.pop()
  elif len(b)>0:
    t+=b.pop()
  if t>k:
    break
  else:
    ans+=1
print(ans)
Problem p02695 (python)

Fixed submission:
from itertools import combinations_with_replacement as cr
n,m,q=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(q)]
nl=[i for i in range(1,m+1)]
ans=0
for v in cr(nl,n):
  s=0
  for a,b,c,d in l:
    if v[b-1]-v[a-1]==c:
      s+=d
  if ans<s:
    ans=s
print(ans)

Buggy submission (verdict: Runtime Error):
from itertools import combinations_with_replacement as cr
n,m,q=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(q)]
nl=[i for i in range(1,m+1)]
ansl=[]
for v in cr(nl,m):
  ans=0
  for a,b,c,d in l:
    if v[b-1]-v[a-1]==c:
      ans+=d
  ansl.append(ans)
print(max(ansl))

Buggy submission (verdict: Runtime Error):
from itertools import combinations_with_replacement as cr
n,m,q=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(q)]
nl=[i for i in range(1,m+1)]
ansl=[]
for v in cr(nl,m):
  ans=0
  for a,b,c,d in l:
    if v[b]-v[a]==c:
      ans+=d
  ansl.append(ans)
print(max(ansl))
Problem p02757 (python)

Fixed submission:
n,p=map(int,input().split())
s=input()
b=1
d=0
l=[0]*p
l[0]=1
ans=0
for i,c in enumerate(s[::-1]):
  if p==2 or p==5:
    if int(c)%p==0:
      ans+=n-i
  else:
    d+=int(c)*b
    d%=p
    l[d]+=1
    b*=10
    b%=p
if p!=2 and p!=5:
  for i in l:
    ans+=i*(i-1)//2
print(ans)

Buggy submission (verdict: Runtime Error):
n,p=map(int,input().split())
s=input()
b=1
d=0
l=[0]*n
ans=0
for c in s[::-1]:
  if p==2 or p==5:
    if int(c)%p==0:
      ans+=1
  else:
    d+=int(c)*b
    d%=p
    l[d]+=1
    b*=10
    b%=p
if p==2 or p==5:
  l[0]=ans
  ans=ans*(ans-1)//2
else:
  for i in l:
    ans+=i*(i-1)//2
print(ans+l[0])

Buggy submission (verdict: Runtime Error):
n,p=map(int,input().split())
s=input()
b=1
d=0
l=[0]*n
ans=0
for c in s[::-1]:
  if p==2 or p==5:
    if int(c)%p==0:
      ans+=1
  else:
    d+=int(c)*b
    d%=p
    l[d]+=1
    b*=10
    b%=p
if p==2 or p==5:
  ans=ans*(ans+1)//2
else:
  for i in l:
    ans+=i*(i-1)//2
print(ans+l[0])
Problem p02596 (python)

Fixed submission:
k = int(input())

if k%2==0 or k%5==0:
  print(-1)
  exit()

mod = 7
cnt = 1
while True:
  if mod%k==0:
    print(cnt)
    exit()
    
  mod *= 10
  mod += 7
  cnt += 1
  mod %= k

Buggy submission (verdict: Runtime Error):
vn = int(input())
cnt = 1
seven = 7

while cnt<n:
  if seven==0:
    print(cnt)
    exit()
  seven = (seven*10+7)%n
  cnt += 1
print(-1)
Problem p03013 (python)

Fixed submission:
n, m = map(int, input().split())
dp = [0]*(n+1)
dp[0] = 1
m_list = [int(input()) for _ in range(m)]
for i in range(1,n+1):
  if i==1:
    if m_list and i==m_list[0]:
      m_list.pop(0)
      dp[i]=0
    else:
      dp[i]=1
  elif m_list and i == m_list[0]:
    m_list.pop(0)
    dp[i] = 0
  else:
    dp[i] = (dp[i-1]+dp[i-2])% 1000000007
print(dp[-1])

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
dp = [0]*(n+1)
dp[0] = 1
m_list = [int(input()) for _ in range(m)]
for i in range(1,n+1):
  if i==1:
    if i==m_list[0]:
      m_list.pop(0)
      dp[i]=0
    else:
      dp[i]=1
  elif m_list and i == m_list[0]:
    m_list.pop(0)
    dp[i] = 0
  else:
    dp[i] = (dp[i-1]+dp[i-2])% 1000000007
print(dp[-1])

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
dp = [0]*(n+1)
dp[0] = 1
m_list = [int(input()) for _ in range(m)]
for i in range(1,n+1):
  if i==1:
    if i==m_list[0]:
      m_list.pop(0)
      dp[i]=0
    else:
      dp[i]=1
  elif m_list and i == m_list[0]:
    m_list.pop(0)
    dp[i] = 0
  else:
    dp[i] = (dp[i-1]+dp[i-2])% 1000000007
print(dp[-1])