Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(map(int, input().split()))
vote_sum = sum(A)
cnt = 0
y = "Yes"
n = "No"

for i in range(N):
	if (A[i]*4*M) >= vote_sum:
		cnt += 1
	if cnt == M:
		print(y)
		break
		
if C < M:
	print(n)

Fixed submission:
from collections import deque
K = int(input())

q = deque([i for i in range(1, 10)])

for i in range(K):
    x = q.popleft()
    amari = x%10
    if amari == 0:
        l, m = 10*x, 10*x+1
        q.append(l)
        q.append(m)
    elif amari == 1:
        l, m, r = x*10, x*10+1, x*10+2
        q.append(l)
        q.append(m)
        q.append(r)
    elif amari == 9:
        l, m = 10*x+8, 10*x+9
        q.append(l)
        q.append(m)
    else:
        l, m, r = 10*x+(amari-1), 10*x+(amari), 10*x+(amari+1)
        q.append(l)
        q.append(m)
        q.append(r)

print(x)

Buggy python submission (verdict: Runtime Error):
for i in range(N):
	if (A[i]*4*M) >= vote_sum:
		cnt += 1
	if cnt == M:
		print(y)
		break
		
if C < M:
	print(n)

Fixed submission:
from collections import deque
K = int(input())

q = deque([i for i in range(1, 10)])

for i in range(K):
    x = q.popleft()
    amari = x%10
    if amari == 0:
        l, m = 10*x, 10*x+1
        q.append(l)
        q.append(m)
    elif amari == 1:
        l, m, r = x*10, x*10+1, x*10+2
        q.append(l)
        q.append(m)
        q.append(r)
    elif amari == 9:
        l, m = 10*x+8, 10*x+9
        q.append(l)
        q.append(m)
    else:
        l, m, r = 10*x+(amari-1), 10*x+(amari), 10*x+(amari+1)
        q.append(l)
        q.append(m)
        q.append(r)

print(x)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(map(int, input().split()))
vote_sum = sum(A)
cnt = 0
y = "Yes"
n = "No"

for i in range(N):
	if (A[i]*4*M) >= vote_sum:
		cnt += 1
	if cnt == M:
		print(y)
		
if C < M:
	print(n)

Fixed submission:
from collections import deque
K = int(input())

q = deque([i for i in range(1, 10)])

for i in range(K):
    x = q.popleft()
    amari = x%10
    if amari == 0:
        l, m = 10*x, 10*x+1
        q.append(l)
        q.append(m)
    elif amari == 1:
        l, m, r = x*10, x*10+1, x*10+2
        q.append(l)
        q.append(m)
        q.append(r)
    elif amari == 9:
        l, m = 10*x+8, 10*x+9
        q.append(l)
        q.append(m)
    else:
        l, m, r = 10*x+(amari-1), 10*x+(amari), 10*x+(amari+1)
        q.append(l)
        q.append(m)
        q.append(r)

print(x)
Buggy python submission (verdict: Runtime Error):
N ,X, Y = map(int, input().split())

X -= 1
Y -= 1
k = [0]*N

for i in range(N-1):
    for j in range(i+1, N):
        a = j-i
        b = abs(i-x)+1+abs(y-j)
        c = abs(j-x)+1+abs(y-i)
        m =  min(a, b, c)
        k[m] += 1

for i in range(1, N):
    print(k[i])

Fixed submission:
N ,X, Y = map(int, input().split())

X -= 1
Y -= 1
k = [0]*N

for i in range(N-1):
    for j in range(i+1, N):
        a = j-i
        b = abs(i-X)+1+abs(Y-j)
        c = abs(j-X)+1+abs(Y-i)
        m =  min(a, b, c)
        k[m] += 1

for i in range(1, N):
    print(k[i])

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

X -= 1
Y -= 1
k = [0]*n

for i in range(N-1):
    for j in range(i+1, N):
        a = j-i
        b = abs(i-x)+1+abs(y-j)
        c = abs(j-x)+1+abs(y-i)
        m =  min(a, b, c)
        k[m] += 1

for i in range(1, N):
    print(k[i])

Fixed submission:
N ,X, Y = map(int, input().split())

X -= 1
Y -= 1
k = [0]*N

for i in range(N-1):
    for j in range(i+1, N):
        a = j-i
        b = abs(i-X)+1+abs(Y-j)
        c = abs(j-X)+1+abs(Y-i)
        m =  min(a, b, c)
        k[m] += 1

for i in range(1, N):
    print(k[i])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))

def group_by_val(list_):
    res = dict()
    for v in list_:
        if v not in res:
            res[v] = [v]
            continue
        res[v].append(v)
    return res

def comb2(list_):
    leng = len(list_)
    if leng == 1:
        return 0
    return (leng*(leng-1)) // 2

grouped_dict = group_by_val(A)

comb_val = 0
comb_dict = dict()
for k in grouped_dict:
    temp = comb2(grouped_dict[k])
    comb_dict[k] = temp
    comb_val += temp

for a in A:
    alist = grouped_dict[a].copy()
    alist.pop()
    ans = comb_val - comb_dict[a] + comb2(alist)
    print(ans)





# ans1 = dict()
# for k in grouped:
#     ans1[k] = comb2(grouped[k])

# ans2 = dict()
# for k in grouped:
#     grouped_ = grouped[k][1:]
#     ans2[k] = comb2(grouped_)

# for a in A:
#     x = 0
#     for k in ans1:
#         if k == a:
#             continue
#         x += ans1[k]
#     print(x + ans2[a])



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

def group_by_val(list_):
    res = dict()
    for v in list_:
        if v not in res:
            res[v] = [v]
            continue
        res[v].append(v)
    return res

def count_leng(dict_):
    res = dict()
    for k in dict_:
        res[k] = len(dict_[k])
    return res

def comb2(list_):
    leng = len(list_)
    if leng == 1:
        return 0
    return (leng*(leng-1)) // 2

grouped_dict = group_by_val(A)
group_leng = count_leng(grouped_dict)

sum_val = 0
for k in grouped_dict:
    sum_val += comb2(grouped_dict[k])

for a in A:
    print(sum_val-(group_leng[a]-1))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))

def grouping_values(list_):
    res = dict()
    for v in list_:
        if v not in res:
            res[v] = [v]
            continue
        res[v].append(v)
    return res

def comb2(list_):
    leng = len(list_)
    if leng == 1:
        return 0
    return (leng*(leng-1)) // 2

grouped = grouping_values(A)

ans1 = dict()
for k in grouped:
    ans1[k] = comb2(grouped[k])

ans2 = dict()
for k in grouped:
    grouped_ = grouped[k][1:]
    ans2[k] = comb2(grouped_)

for a in A:
    x = 0
    for k in ans1:
        if k == a:
            continue
        x += ans1[k]
    print(x + ans2[a])



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

def group_by_val(list_):
    res = dict()
    for v in list_:
        if v not in res:
            res[v] = [v]
            continue
        res[v].append(v)
    return res

def count_leng(dict_):
    res = dict()
    for k in dict_:
        res[k] = len(dict_[k])
    return res

def comb2(list_):
    leng = len(list_)
    if leng == 1:
        return 0
    return (leng*(leng-1)) // 2

grouped_dict = group_by_val(A)
group_leng = count_leng(grouped_dict)

sum_val = 0
for k in grouped_dict:
    sum_val += comb2(grouped_dict[k])

for a in A:
    print(sum_val-(group_leng[a]-1))
Buggy python submission (verdict: Runtime Error):
from decimal import *

getcontext().prec = 10000
a, b, c = map(int, input().split())

l = Decimal(a).sqrt() + Decimal(b).sqrt()
r = Decimal(c).sqrt()

if l < r:
    print("Yes")
else:
    print("No")

Fixed submission:
K = int(input())

s = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51".split(", ")

print(s[K-1])
Buggy python submission (verdict: Time Limit Exceeded):
N, A, B = map(int, input().split())

l = ""
while len(l) < N:
    for i in range(A):
        if len(l) < N:
            l += "b"
    for j in range(B):
        if len(l) < N:
            l += "r"
    

print(l.count("b"))

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

x = (N // (A+B)) * A
y = N%(A+B)

if y >= A:
    x += A
else:
    x += y

print(x)
Buggy python submission (verdict: Runtime Error):
A = [list(map(int, input().split())) for i in range(3)]
N = int(input())
b = []
for i in range(N):
	b.append(int(input()))
	
yoko = A
tate = [[], [], []]
for row in A:
	for i in range(3):
		tate[i].append(row[i])
naname = [[A[0][0], A[1][1], A[2][2]], [A[0][3], A[1][1], A[2][0]]]

all = yoko + tate + naname

y = 0
chk = 0
for kumi in all:
	for k in kumi:
		if k in b:
			chk += 1
		else:
			continue
	if chk == 3:
		print("Yes")
		y = 1
		break
	else:
		chk = 0
		
if y == 0:
	print("No")

Fixed submission:
A = [list(map(int, input().split())) for i in range(3)]
N = int(input())
b = []
for i in range(N):
	b.append(int(input()))
	
yoko = A
tate = [[], [], []]
for row in A:
	for i in range(3):
		tate[i].append(row[i])
naname = [[A[0][0], A[1][1], A[2][2]], [A[0][2], A[1][1], A[2][0]]]

all = yoko + tate + naname

y = 0
chk = 0
for kumi in all:
	for k in kumi:
		if k in b:
			chk += 1
		else:
			continue
	if chk == 3:
		print("Yes")
		y = 1
		break
	else:
		chk = 0
		
if y == 0:
	print("No")
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
p = list(map(int, input().split()))

# i番目の期待値は(1/p_i)*(sum(1からp_iまでの和)))

def get_E(x):
    return (sum(list(range(1,x+1))))/x

E_list = [get_E(p_i) for p_i in p]


ans = -1
for i in range(n-k+1):
    t = sum(E_list[i:i+k])
    ans = max(ans, t)

print(ans)

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

Es = [(1+p_i)/2 for p_i in p]

t = sum(Es[0:k])
ans = t

for i in range(n-k):
    t -= Es[i]
    t += Es[i+k]
    ans = max(ans,t)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
p = list(map(int, input().split()))

def calc(n):
    return sum([i for i in range(1, n+1)]) / n
ex = []
for i in p:
    ex.append(calc(i))
    
max_ex = 0
for i in range(0, N-(K-1)):
    temp = sum(ex[i:i+K])
    if temp > max_ex:
        max_ex = temp

print(max_ex)

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

Es = [(1+p_i)/2 for p_i in p]

t = sum(Es[0:k])
ans = t

for i in range(n-k):
    t -= Es[i]
    t += Es[i+k]
    ans = max(ans,t)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
p = list(map(int, input().split()))

def calc(n):
    return sum([i for i in range(1, n+1)]) / n

ex = []
for i in p:
    ex.append(calc(i))
max_ex = 0
for i in range(0, N-(K-1)):
    temp = sum(ex[i:i+K])
    if temp > max_ex:
        max_ex = temp

print(max_ex)

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

Es = [(1+p_i)/2 for p_i in p]

t = sum(Es[0:k])
ans = t

for i in range(n-k):
    t -= Es[i]
    t += Es[i+k]
    ans = max(ans,t)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
p = list(map(int, input().split()))

def calc(n):
    return sum([i for i in range(1, n+1)]) / n

ex = []
for i in p:
    ex.append(calc(i))
max_ex = 0
for i in range(0, N-(K-1)):
    temp = sum(ex[i:i+K])
    if temp >= max_ex:
        max_ex = temp

print(max_ex)

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

Es = [(1+p_i)/2 for p_i in p]

t = sum(Es[0:k])
ans = t

for i in range(n-k):
    t -= Es[i]
    t += Es[i+k]
    ans = max(ans,t)

print(ans)
Buggy python submission (verdict: Runtime Error):
H, N  = map(int, input().split())
a = input()

s = 0
for ai in a:
    a = int(ai)
    s += a

if H > s:
    print("No")
else:
    print("Yes")

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

s = 0
for i in a:
    s += i

if H > s:
    print("No")
else:
    print("Yes")

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

s = 0
for i in range(N):
    a = int(input())
    s += a

if H > s:
    print("No")
else:
    print("Yes")

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

s = 0
for i in a:
    s += i

if H > s:
    print("No")
else:
    print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
A, B, K = map(int, input().split())

while(K>0):
    if A == 0 and B == 0:
        break
    if A > 0:
        A -= 1
        K -= 1
        continue
    if B > 0:
        B -= 1
        K -= 1
        continue

print(A, B)

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

if A == K:
    print(0, B)
elif A > K:
    print(A-K, B)
elif K > A:
    K -= A
    A = 0
    if B == K:
        print(A, 0)
    elif K > B:
        print(A, 0)
    elif B > K:
        print(A, B-K)

Buggy python submission (verdict: Time Limit Exceeded):
A, B, K = map(int, input().split())

while(K>0):
    if A == 0 and B == 0:
        break
    if A > 0:
        A -= 1
        K -= 1
        continue
    if B > 0:
        B -= 1
        K -= 1
        continue

print(A, B)

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

if A == K:
    print(0, B)
elif A > K:
    print(A-K, B)
elif K > A:
    K -= A
    A = 0
    if B == K:
        print(A, 0)
    elif K > B:
        print(A, 0)
    elif B > K:
        print(A, B-K)
Buggy python submission (verdict: Runtime Error):
import math

a, b = map(int, input().split())

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

print(lcm(a, b))


Fixed submission:
def g(x, y):
	while y > 0:
		x, y = y, x%y
	return x
def l(x, y):
	return x // g(x, y) * y

a, b = map(int, input().split())


print(l(a,b))
Buggy python submission (verdict: Runtime Error):
a, b, c = map(int, list(input())

a += b 
a += c

if a > 22:
    print("bust")
else:
    print("win")

Fixed submission:
l = input()
a, b, c = map(int, l.split())

sum=0
sum+=a
sum+=b
sum+=c

if sum >= 22:
    print("bust")
else:
    print("win")

Buggy python submission (verdict: Runtime Error):
a, b, c = map(int, input())

a += b 
a += c

if a > 22:
    print("bust")
else:
    print("win")

Fixed submission:
l = input()
a, b, c = map(int, l.split())

sum=0
sum+=a
sum+=b
sum+=c

if sum >= 22:
    print("bust")
else:
    print("win")
Buggy python submission (verdict: Runtime Error):
N, A, B = map(int, input())
T = N*A
print(max(T,B))

Fixed submission:
N, A, B = map(int, input().split())
T = N*A
print(min(T,B))
Buggy python submission (verdict: Runtime Error):
A = input()
B = input()

m = max(A, B)
m = m + m +1

print(m)

Fixed submission:
A, B = (int(x) for x in input().split())

if A == B:
	print(A+B)
else :
	m = max(A, B)
	m = m*2 - 1
	print(m)
Buggy python submission (verdict: Runtime Error):
import re

s = input()
li = s.splite("/")
month = int(li[1])

if month > 4:
  print('TBD')
else:
  print("Heisei")

return 0

Fixed submission:
import re

s = input()
li = s.split("/")
month = int(li[1])

if month > 4:
  print('TBD')
else:
  print("Heisei")

Buggy python submission (verdict: Runtime Error):
import re

s = input()
li = s.splite("/")
month = int(li[1])

if month > 4:
  print('TBD')
else:
  print("Heisei")

Fixed submission:
import re

s = input()
li = s.split("/")
month = int(li[1])

if month > 4:
  print('TBD')
else:
  print("Heisei")
Buggy python submission (verdict: Runtime Error):
s = input()
t = input()

s = sorted(s)
t = reversed(t)

if s < t:
    print('Yes')
else:
    print('No') 

Fixed submission:
s = input()
t = input()

s = ''.join(sorted(s))
t = ''.join(sorted(t, reverse=True))

if s < t:
    print('Yes')
else:
    print('No')

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
t = input()

sl = list(s)
sn = len(sl)

from itertools import permutations

sp = []
for v in permutations(sl, sn):
    sp.append("".join(list(v)))

tl = list(t)
tn = len(tl)
tp = []
for v in permutations(tl, tn):
    tp.append("".join(list(v)))

f = False
for se in sp:
    for te in tp:
        if se < te:
            f = True
            break
    if f:
        break

if f:
    print("Yes")
else:
    print("No")

Fixed submission:
s = input()
t = input()

s = ''.join(sorted(s))
t = ''.join(sorted(t, reverse=True))

if s < t:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(int, input().split()))

num_set = set()
for a_i in a:
    if a_i in num_set:
        continue
    num_set.add(a_i)

ans = 0
for num in num_set:
    num_of_num = a.count(num)
    # print(num, num_of_num)
    if num == num_of_num:
        continue
    if num_of_num < num:
        ans += num_of_num
        continue
    ans += num_of_num-num

print(ans)

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

num_dict = dict()
for a_i in a:
    if a_i in num_dict:
        num_dict[a_i] += 1
        continue
    num_dict[a_i] = 1

ans = 0
for num in num_dict:
    if num_dict[num] == num:
        continue
    if num_dict[num] < num:
        ans += num_dict[num]
        continue
    ans += num_dict[num]-num

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

f = True
cnt = 0
while(f):
  for i in range(N):
    if A[i]%2 == 0:
      A[i] = A[i]//2
      continue
    f = False
  if f:
    cnt += 1

print(cnt)


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

f = True
cnt = 0
while(f):
	for i in range(N):
		if A[i]%2 == 0:
			A[i] = A[i]//2
		else:
			f = False
			break
	if f:
		cnt += 1

print(cnt)
Buggy python submission (verdict: Runtime Error):
n = int(input())
d = list(map(int, input().split()))
m = int(input())
t = list(map(int, input().split()))

# n 問題案数
# m 必要問題数
# d 難易度
# t 難易度

freq_of_val_in_d = dict()
freq_of_val_in_t = dict()

for v in d:
    if v in freq_of_val_in_d:
        freq_of_val_in_d[v] += 1
        continue
    freq_of_val_in_d[v] = 1

for v in t:
    if v in freq_of_val_in_t:
        freq_of_val_in_t[v] += 1
        continue
    freq_of_val_in_t[v] = 1

f = True
for v in t:
    if freq_of_val_in_t[v] > freq_of_val_in_d[v]:
        f = False

if f:
    print("YES")
else:
    print("NO")




Fixed submission:
from collections import Counter
input()
c1 = Counter(map(int, input().split()))
input()
c2 = Counter(map(int, input().split()))
print("YES" if all(c1[k] >= v for k, v in c2.items()) else "NO")
Buggy python submission (verdict: Runtime Error):
s = input()
for i in range(97, 113+1):
    if s.find(chr(i)) == -1:
        print(c)
        exit()
    
print('None')

Fixed submission:
s = input()
for c in 'abcdefghijklmnopqrstuvwxyz':
    if s.find(c) == -1:
        print(c)
        exit()
    
print('None')
Buggy python submission (verdict: Runtime Error):
w = input()

f = True
for s in w:
  a = w.count(s)
  if a%2 != 0:
    f = Flase
    break
 
if f:
  print("Yes")
else:
  print("No")

Fixed submission:
w = input()
 
f = True
for s in w:
	a = w.count(s)
	if a%2 != 0:
		f = False
		break
 
if f:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Time Limit Exceeded):
line1 = input()
line2 = input()

n, k = tuple([int(val) for val in line1.split()])
a_list = [int(val) for val in line2.split()]

prev_sum = sum(a_list[0:k])
for i in range(k, n):
    current_sum = sum(a_list[i-k+1:i+1])
    if current_sum > prev_sum:
        print("Yes")
    else:
        print("No")
    prev_sum = current_sum

Fixed submission:
line1 = input()
line2 = input()

n, k = tuple([int(val) for val in line1.split()])
a_list = [int(val) for val in line2.split()]

prev_sum = sum(a_list[0:k])
for i in range(k, n):
    current_sum = prev_sum - a_list[i-k] + a_list[i]
    if current_sum > prev_sum:
        print("Yes")
    else:
        print("No")
    prev_sum = current_sum
Buggy python submission (verdict: Runtime Error):
ans = 1
lim = 10**18
n = int(input())
a = list(map(int, input().split()))
for x in a:
	ans *= x
if ans > lim:
	print(-1)
else:
	print(ans)

Fixed submission:
a, b = map(int, input().split())
print(a*b)
Buggy python submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
if c -2*(a+b)>0:
    print('Yes')
elif 4*a*b < (c-b-a)**2 or math.sqrt(a*b)<(c-b-a)/2:
    print('Yes')
else:
    print('No')

Fixed submission:
a, b, c = map(int, input().split())
if c -2*(a+b)>0:
    print('Yes')
elif c>=a+b and 4*a*b < (c-b-a)**2:
    print('Yes')
elif a == c or b == c:
    print('No')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
N = int(input())
Q = []
for i in range(N):
    q = input()
    if len(q)>1:
        q = q.split()
    else:
        q = [q]
    Q.append(q)
for i in range(N):
    if len(Q[i])==1:
        S = S[::-1]
    if len(Q[i])>1:
        if Q[i][1]=='1':
            S.insert(0, Q[i][2])
        else:
            S.append(Q[i][2])
print(''.join(S))

Fixed submission:
from collections import deque
S = deque(input())
N = int(input())
Q = []
gyaku = 0
for i in range(N):
    q = input()
    if len(q)>1:
        q = q.split()
    else:
        q = [q]
    Q.append(q)
#print(Q)
for i in range(N):
    if len(Q[i])==1:
        gyaku +=1
        #print(S)
    if len(Q[i])>1:
        if Q[i][1]=='1'and gyaku%2==0:
            S.appendleft(Q[i][2])
        elif Q[i][1]=='1'and gyaku%2==1:
            S.append(Q[i][2])
            #print(S)
        elif Q[i][1]=='2'and gyaku%2==0:
            S.append(Q[i][2])
        else:
            S.appendleft(Q[i][2])
            #print(S)
if gyaku%2==0:
    #print(S)
    print(''.join(S))
else:
    S = list(S)
    print(''.join(S[::-1]))
Buggy python submission (verdict: Time Limit Exceeded):
N, P = map(int, input().split())
S = input()
ans = 0
mod = [0]*P
if P==2 or P==5:
    for i in range(N):
        if int(S[i])%P==0:
            ans+=i+1
    print(ans)
else:
    un1 = 0
    un = 0
    for i in range(N-1, -1, -1):
        a = int(S[i])*10**un + un1
        un += 1
        un1 = a
        mod[a%P]+=1
    ans += mod[0]  
    for i in range(P):
        ans += mod[i]*(mod[i]-1)/2
    print(int(ans))

Fixed submission:
N, P = map(int, input().split())
S = input()
ans = 0
mod = [0]*P
if P==2 or P==5:
    for i in range(N):
        if int(S[i])%P==0:
            ans+=i+1
    print(ans)
else:
    un1 = 0
    un = 0
    for i in range(N-1, -1, -1):
        #a =int(S[i])*10**un + un1
        a =int(S[i])*pow(10,un,P)+(un1)%P
        un += 1
        un1 = a
        mod[a%P]+=1
    ans += mod[0]  
    for i in range(P):
        ans += mod[i]*(mod[i]-1)/2
    print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
N, P = map(int, input().split())
s = list(input())
s = [int(i) for i in s]
S = []
ans = 0
for i in range(len(s)+1):
    for j in range(1, len(s)+1-i):
        A = 0
        for k in range(len(s[i:i+j])):
            A += s[i+k]*10**(j-k-1)
            
        if A%P==0:
            ans +=1
print(ans)

Fixed submission:
N, P = map(int, input().split())
S = input()
ans = 0
mod = [0]*P
if P==2 or P==5:
    for i in range(N):
        if int(S[i])%P==0:
            ans+=i+1
    print(ans)
else:
    un1 = 0
    un = 0
    for i in range(N-1, -1, -1):
        #a =int(S[i])*10**un + un1
        a =int(S[i])*pow(10,un,P)+(un1)%P
        un += 1
        un1 = a
        mod[a%P]+=1
    ans += mod[0]  
    for i in range(P):
        ans += mod[i]*(mod[i]-1)/2
    print(int(ans))