Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import math
import itertools

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

X = [[0]*D+1]*N+1

for n in range(N):
    X[n] = list(map(int, input().split()))

def distance(x, y):
    dis = 0
    for d in range(D):
        dis += abs(x[d] - y[d]) ** 2
    
    return math.sqrt(dis).is_integer()
    
distance(X[1], X[2])

count = 0

for c in itertools.combinations(list(range(N)), 2):
    if distance(X[c[0]], X[c[1]]):
        count += 1
        
print(count)

Fixed submission:
import math
import itertools

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

X = [[0]*(D+1)]*(N+1)

for n in range(N):
    X[n] = list(map(int, input().split()))

def distance(x, y):
    dis = 0
    for d in range(D):
        dis += abs(x[d] - y[d]) ** 2
    
    return math.sqrt(dis).is_integer()
    
distance(X[1], X[2])

count = 0

for c in itertools.combinations(list(range(N)), 2):
    if distance(X[c[0]], X[c[1]]):
        count += 1
        
print(count)

Buggy python submission (verdict: Runtime Error):
import math
import itertools

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

X = [[0]*D]*N

for n in range(N):
    X[n] = list(map(int, input().split()))
    
#print(X)

def distance(x, y):
    dis = 0
    for d in range(D):
        dis += abs(x[d] - y[d]) ** 2
    
    #print(math.sqrt(dis))
    return math.sqrt(dis).is_integer()
    
distance(X[1], X[2])

#print(list(range(N)))

count = 0

for c in itertools.combinations(list(range(N)), 2):
    #print(c)
    if distance(X[c[0]], X[c[1]]):
        count += 1
        
print(count)

Fixed submission:
import math
import itertools

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

X = [[0]*(D+1)]*(N+1)

for n in range(N):
    X[n] = list(map(int, input().split()))

def distance(x, y):
    dis = 0
    for d in range(D):
        dis += abs(x[d] - y[d]) ** 2
    
    return math.sqrt(dis).is_integer()
    
distance(X[1], X[2])

count = 0

for c in itertools.combinations(list(range(N)), 2):
    if distance(X[c[0]], X[c[1]]):
        count += 1
        
print(count)
Buggy python submission (verdict: Runtime Error):
import math
import itertools

L, R = map(int, input().split())

mods = []

for c in itertools.combinations(range(L, R+1), 2):
    # print(c)
    mods.append((c[0]*c[1]) % 2019)
    
print(min(mods))

Fixed submission:
import itertools

L, R = map(int, input().split())

R = min(R, L+2019)

mods = []

for c in list(itertools.combinations(list(range(L, R+1)),2)):
    mods.append((c[0]*c[1]) % 2019)

print(min(mods))
Buggy python submission (verdict: Runtime Error):
import math

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

# Cで割り切れる数
div_c_min = math.ceil(A/C)
div_c_max = math.floor(B/C)
div_c_num = div_c_max - div_c_min + 1
#print(div_c_min, div_c_max)
#print(div_c_num)

# Dで割り切れる数
div_d_min = math.ceil(A/D)
div_d_max = math.floor(B/D)
div_d_num = div_d_max - div_d_min + 1
#print(div_d_min, div_d_max)
#print(div_d_num)

# 最小公倍数
def lcm(x, y):
    return (x * y) // math.gcd(x, y)

# CとDの公倍数で割り切れる数
div_cd_min = math.ceil(A / lcm(C, D))
div_cd_max = math.floor(B / lcm(C, D))
div_cd_num = div_cd_max - div_cd_min + 1
#print(div_cd_min, div_cd_max)
#print(div_cd_num)

numAtoB = B - A + 1
print(numAtoB - (div_c_num + div_d_num - div_cd_num))

Fixed submission:

import math
import fractions

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

def lcm(a, b):
  return (a * b) // fractions.gcd(a, b)

# CとDの最小公倍数で割り切れる数
lcm = lcm(C, D)

ans = B-A+1 - (B//C-(A-1)//C) - (B//D-(A-1)//D) + (B//(lcm)-(A-1)//(lcm))

print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
import sympy as sym

def fib(n):
    x = sym.symbols('x',nonnegative=True,integer=True)
    Fib=1/sym.sqrt(5)*(((1+sym.sqrt(5))/2)**(n-1)-((1-sym.sqrt(5))/2)**(n-1)) #一般項の式
    result=Fib.subs(x,n)
    result=result.evalf()
    return int(result)


N, M = map(int, input().split())
a = [-1]
for i in range(M):
    a.append(int(input()))
    
for i in range(M-1):
    if a[i+1] == (a[i] + 1):
        print(0)
        exit()
    
combi = 1

for i in range(len(a)-1):
    dis = a[i+1] - a[i]
    combi *= fib(dis)
    
dis = N+1 - a[-1]
combi *= fib(dis)

print(combi % 1000000007)

Fixed submission:
def fib(n):
    a, b = 0, 1
    if n == 1:
        return a
    elif n == 2:
        return b
    else:
        for i in range(n-2):
            a, b = b, a + b
        return b
    
N, M = map(int, input().split())
a = [-1]
for i in range(M):
    a.append(int(input()))
    
for i in range(M-1):
    if a[i+1] == (a[i] + 1):
        print(0)
        exit()
    
combi = 1

for i in range(len(a)-1):
    dis = a[i+1] - a[i]
    #print(dis)
    combi *= fib(dis)
    #print(a[i])
    
dis = N+1 - a[-1]
#print(dis)
combi *= fib(dis)

print(combi % 1000000007)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, raw_input().strip().split())

if k == 0:
    sz = 1 << n
    sz -= 1
    out = [' '.join([str(i), str(i)]) for i in xrange(sz + 1)]
    print ' '.join(out)

elif k == 1:
    if m == 2:
        print 0, 1, 0, 2, 3, 1, 3, 2
    else:
        print -1
else:
    print -1

Fixed submission:
n, k = map(int, raw_input().strip().split())

if k == 0:
    sz = 1 << n
    sz -= 1
    out = [' '.join([str(i), str(i)]) for i in xrange(sz + 1)]
    print ' '.join(out)
    exit()

m = 1 << n
if k >= m:
    print -1
    exit()

if n < 2:
    print -1
    exit()

l = []
for i in xrange(m):
    if i == k: continue
    l.append(i)

l.append(k)
for i in xrange(m - 1, -1, -1):
    if i == k: continue
    l.append(i)
l.append(k)

print ' '.join(map(str, l))
Buggy python submission (verdict: Runtime Error):
n = input()
s = raw_input().strip()
r = 0
for i in xrange(n):
  if s[i] == 'R': r += 1
  else: b += 1

if r > b: print "Yes"
else: print "No"

Fixed submission:
n = input()
s = raw_input().strip()
r = b = 0
for i in xrange(n):
  if s[i] == 'R': r += 1
  else: b += 1
     
if r > b: print "Yes"
else: print "No"
Buggy python submission (verdict: Runtime Error):
from sys import stdin, setrecursionlimit as lim

lim(100001)

n, m = map(int, raw_input().strip().split())
inp = stdin.readlines()

g1 = ([] for i in xrange(n + 1))
g2 = ([] for i in xrange(n + 1))
ans1 = [0 for i in xrange(n + 1)]
ans2 = [0 for i in xrange(n + 1)]

for line in inp:
    u, v = map(int, line.strip().split())
    g1[u].append(v)
    g2[v].append(u)

def dfs1(u):
    if ans1[u] != 0: return ans1[u]
    ret = 0
    for v in g1[u]:
        if ans1[v] != 0: ret = max(ret, ans1[v])
        else: ret = max(ret, dfs1(v))
    ret += 1
    ans1[u] = ret
    return ans1[u]

def dfs2(u):
    if ans2[u] != 0: return ans2[u]
    ret = 0
    for v in g2[u]:
        if ans2[v] != 0: ret = max(ret, ans2[v])
        else: ret = max(ret, dfs2(v))
    ret += 1
    ans2[u] = ret
    return ans2[u]

ans = 0
for i in xrange(1, n + 1):
    if ans1[i] == 0: ans = max(ans, dfs1(i))
for i in xrange(1, n + 1):
    if ans2[i] == 0: ans = max(ans, dfs2(i))

print ans - 1

Fixed submission:
from sys import stdin, setrecursionlimit as lim

lim(100001)

n, m = map(int, raw_input().strip().split())
inp = stdin.readlines()

g1 = [[] for i in xrange(n + 1)]
g2 = [[] for i in xrange(n + 1)]
ans1 = [0 for i in xrange(n + 1)]
ans2 = [0 for i in xrange(n + 1)]

for line in inp:
    u, v = map(int, line.strip().split())
    g1[u].append(v)
    g2[v].append(u)

def dfs1(u):
    if ans1[u] != 0: return ans1[u]
    ret = 0
    for v in g1[u]:
        if ans1[v] != 0: ret = max(ret, ans1[v])
        else: ret = max(ret, dfs1(v))
    ret += 1
    ans1[u] = ret
    return ans1[u]

def dfs2(u):
    if ans2[u] != 0: return ans2[u]
    ret = 0
    for v in g2[u]:
        if ans2[v] != 0: ret = max(ret, ans2[v])
        else: ret = max(ret, dfs2(v))
    ret += 1
    ans2[u] = ret
    return ans2[u]

ans = 0
for i in xrange(1, n + 1):
    if ans1[i] == 0: ans = max(ans, dfs1(i))
for i in xrange(1, n + 1):
    if ans2[i] == 0: ans = max(ans, dfs2(i))

print ans - 1
Buggy python submission (verdict: Runtime Error):
n = input()
l = []
isz = 0
for i in xrange(n):
    x, y, h = map(int, raw_input().strip().split())
    if h == 0: isz += 1
    l.append([x, y, h])

assert isz != n

ans = [0,0,0]

for cx in xrange(101):
    for cy in xrange(101):
        H = 0
        zH = int(1e18)
        poss = True
        for xyh in l:
            x, y, h = xyh
            tx = abs(cx - x) + abs(cy - y)
            if h != 0:
                nH = tx + h
                if H != 0 and nH != H:
                    poss = False
                    break
                elif H == 0: H = nH
            elif h == 0:
                zH = min(zH, tx + h)
                
        if poss:
            ans = [cx, cy, H]
            break
        
    if poss: break
    
if ans != [0, 0, 0]:
    check = True
    for xyh in l:
        x, y, h = xyh
        tx = abs(cx - x) + abs(cy - y)
        assert h == max(ans[2] - tx, 0)
 
print ans[0], ans[1], ans[2]

Fixed submission:
n = input()
l = []
isz = 0
for i in xrange(n):
    x, y, h = map(int, raw_input().strip().split())
    if h == 0: isz += 1
    l.append([x, y, h])

assert isz != n

ans = [0,0,0]

for cx in xrange(101):
    for cy in xrange(101):
        H = 0
        zH = int(1e18)
        poss = True
        for xyh in l:
            x, y, h = xyh
            tx = abs(cx - x) + abs(cy - y)
            if h != 0:
                nH = tx + h
                if H != 0 and nH != H:
                    poss = False
                    break
                elif H == 0: H = nH
            elif h == 0:
                zH = min(zH, tx)

        if poss:
            if H > zH: poss = False
             
        if poss:
            ans = [cx, cy, H]
            break
        
    if poss: break
    
if ans != [0, 0, 0]:
    check = True
    for xyh in l:
        x, y, h = xyh
        tx = abs(cx - x) + abs(cy - y)
        assert h == max(ans[2] - tx, 0)

print ans[0], ans[1], ans[2]
Buggy python submission (verdict: Runtime Error):
no = input()
c = false
while no > 0:
  if no%10 == 7:
    c = true
if c == true:
  print("Yes")
else :
  print("No")

Fixed submission:
def check(n):
	while n > 0:
		if n%10 == 7:
			return "Yes"
		n = int(n/10)
	return "No"

no = int(input())
print(check(no))

Buggy python submission (verdict: Runtime Error):
n=int(input())
s=list(input())

def my_index_multi(l, x):
    return [i for i, _x in enumerate(l) if _x == x]

R_index = my_index_multi(s,'R')
G_index = my_index_multi(s,'G')
B_index = my_index_multi(s,'B')

for i in range(len(R_index)):
    R_index[i] += 1
for j in range(len(G_index)):
    G_index[j] += 1
for k in range(len(B_index)):
    B_index[k] += 1

count = 0
for i in range(len(R_index)):
    for j in range(len(G_index)):
        for k in range(len(B_index)):
            li = [R_index[i],G_index[j],B_index[k]]
            li.sort()
            if (li[1]*2 != li[0]+li[2]):
                count = count +1

#print(R_index)
#print(G_index)
#print(B_index)
print(count)

Fixed submission:
a=input()
q = -1
if a[0]=='7':
    q =1
elif a[1]=='7':
    q = 1
elif a[2]=='7':
    q = 1

if q > 0:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
s = list(input())

if s[0] == s[1] or s[1] == s[2] or s[2] == s[3] or s[3] == s[4]:
    print('Bad')
else:
    print('Good')


Fixed submission:
s = list(input())

if s[0] == s[1] or s[1] == s[2] or s[2] == s[3]:
    print('Bad')
else:
    print('Good')
Buggy python submission (verdict: Runtime Error):
import math

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

lcm = c*d//math.gcd(c,d)

b_num = b - b//c - b//d + b//lcm
a_num = a - a//c - a//d + a//lcm

ans = b_num - a_num + 1

print(int(ans))

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

def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

lcm = c*d//gcd(c,d)

b_num = b - b//c - b//d + b//lcm
a_num = (a-1) - (a-1)//c - (a-1)//d + (a-1)//lcm


ans = b_num - a_num

print(ans)
Buggy python submission (verdict: Runtime Error):
w, h, x, y= map(int,input().split())

f = 0
if x <= w/2 and y <= h/2:
    if y/x == h/w and x == w/2 and y == h/2:
        s = h*w/2
        f = 1
    elif y/x == h/w and (x < w/2 or y < h/2):
        s = h*w/2
    else:
        s1 = x*h
        s2 = w*y
        s = max(s1,s2)
        if s1 == s2:
            f=1
    print(s,f)
elif x > w/2 and y <= h/2:
    if (h-y)/x == h/w:
        s = h*w/2
    else:
        s1 = (w-x)*h
        s2 = w*y
        s = max(s1,s2)
        if s1 == s2:
            f=1
    print(s,f)
elif x > w/2 and y > h/2:
    if y/x == h/w:
        s = h*w/2
    else:
        s1 = (w-x)*h
        s2 = w*(h-y)
        s = max(s1,s2)
        if s1 == s2:
            f=1
    print(s,f)
elif x <= w/2 and y > h/2:
    if (h-y)/x == h/w:
        s = h*w/2
    else:
        s1 = x*h
        s2 = w*(h-y)
        s = max(s1,s2)
        if s1 == s2:
            f=1
    print(s,f)

Fixed submission:
w, h, x, y= map(int,input().split())

f = 0
s = h*w/2
if x == w/2 and y == h/2:
    f = 1

print(s,f)

Buggy python submission (verdict: Runtime Error):
w, h, x, y= map(int,input().split())

f = 0
if x <= w/2 and y <= h/2:
    if y/x == h/w and x == w/2 and y == h/2:
        s = h*w/2
        f = 1
    elif y/x == h/w:
        s = h*w/2
    else:
        s1 = x*h
        s2 = w*y
        s = max(s1,s2)
        if s1 == s2:
            f=1
    print(s,f)
elif x > w/2 and y <= h/2:
    if (h-y)/x == h/w:
        s = h*w/2
    else:
        s1 = (w-x)*h
        s2 = w*y
        s = max(s1,s2)
        if s1 == s2:
            f=1
    print(s,f)
elif x > w/2 and y > h/2:
    if y/x == h/w:
        s = h*w/2
    else:
        s1 = (w-x)*h
        s2 = w*(h-y)
        s = max(s1,s2)
        if s1 == s2:
            f=1
    print(s,f)
elif x <= w/2 and y > h/2:
    if (h-y)/x == h/w:
        s = h*w/2
    else:
        s1 = x*h
        s2 = w*(h-y)
        s = max(s1,s2)
        if s1 == s2:
            f=1
    print(s,f)

Fixed submission:
w, h, x, y= map(int,input().split())

f = 0
s = h*w/2
if x == w/2 and y == h/2:
    f = 1

print(s,f)
Buggy python submission (verdict: Runtime Error):
import math

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

a.sort()

if n == 2:
    print(a[1])
elif n == 3:
    gcd1 = math.gcd(a[0],a[1])
    gcd2 = math.gcd(a[1],a[2])
    gcd3 = math.gcd(a[0],a[2])
    ans = [gcd1, gcd2, gcd3]
    ans.sort()

    print(ans[-1])

else:
    gcd1 = math.gcd(a[0],a[1])
    gcd2 = math.gcd(a[1],a[2])
    gcd3 = math.gcd(a[0],a[2])

    for i in range(3,n):
        if math.gcd(gcd1, a[i]) < gcd1:
            gcd1 = math.gcd(gcd1, a[i])

    for i in range(3,n):
        if math.gcd(gcd2, a[i]) < gcd2:
            gcd2 = math.gcd(gcd2, a[i])

    for i in range(3,n):
        if math.gcd(gcd3, a[i]) < gcd3:
            gcd3 = math.gcd(gcd3, a[i])

    ans = [gcd1, gcd2, gcd3]
    ans.sort()

    print(ans[-1])

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

time = 0
for i in range(n):
    if a[i] < 0:
        time += 1
        a[i] = -a[i]

sum = 0
for i in range(n):
    sum += a[i]

a.sort()

if time % 2 == 0:
    print(sum)
else:
    print(sum - a[0] * 2)
Buggy python submission (verdict: Runtime Error):
a,b = map(int,input().split())
if a-b >= 2:
  print(2a-1)
elif b-a >= 2:
  print(2b-1)
else:
  print(a+b)

Fixed submission:
a,b = map(int,input().split())
if a-b >= 2:
  print(2*a-1)
elif b-a >= 2:
  print(2*b-1)
else:
  print(a+b)
Buggy python submission (verdict: Runtime Error):
N, Q = map(int,input().split())
S = input()

count_list = [0]*(N+1)

for i in range(N):
    if S[i:i+2] == 'AC':
        count_list[i+1] = count_list[i] + 1
    else:
        count_list[i+1] = count_list[i]

for i in range(Q):
    l, r = map(int,input().split())
    print(count_list[r-1] - count_list[l-1])

Fixed submission:
b = input()
if b == "A":
  print("T")
elif b == "T":
  print("A")
elif b == "C":
  print("G")
elif b == "G":
  print("C")
Buggy python submission (verdict: Runtime Error):
N = int(input())
b_list = list(map(int,input().split()))
answer_list = []

for i in range(N):
    if b_list[i] > i+1:
        print(-1)
        break


    
    for j in range(N-i, 0, -1):
        
        if b_list[j-1] == j:
            answer_list.append(b_list[j-1])
            b_list.pop(j-1)
            
            break

answer_list.reverse()


for i in range(N):
    print(answer_list[i])

Fixed submission:
N = int(input())
b_list = list(map(int,input().split()))
answer_list = []
check = 0

for i in range(N):
    if b_list[i] > i+1:
        print(-1)
        check = 1
        break

if check == 0:
    for i in range(N):     
        for j in range(N-i, 0, -1):
            
            if b_list[j-1] == j:
                answer_list.append(b_list[j-1])
                b_list.pop(j-1)
                
                break

    answer_list.reverse()


    for i in range(N):
        print(answer_list[i])

Buggy python submission (verdict: Runtime Error):
N = int(input())
b_list = list(map(int,input().split()))
answer_list = []

for i in range(N):
    if b_list[i] > i+1:
        print(-1)
        break

for i in range(N): 
    
    for j in range(N-i, 0, -1):
        
        if b_list[j-1] == j:
            answer_list.append(b_list[j-1])
            b_list.pop(j-1)
            
            break

answer_list.reverse()


for i in range(N):
    print(answer_list[i])

Fixed submission:
N = int(input())
b_list = list(map(int,input().split()))
answer_list = []
check = 0

for i in range(N):
    if b_list[i] > i+1:
        print(-1)
        check = 1
        break

if check == 0:
    for i in range(N):     
        for j in range(N-i, 0, -1):
            
            if b_list[j-1] == j:
                answer_list.append(b_list[j-1])
                b_list.pop(j-1)
                
                break

    answer_list.reverse()


    for i in range(N):
        print(answer_list[i])
Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())
h, w = mao(int, input().split())

print(W*h + H*w -(h+w-1))

Fixed submission:
H, W = map(int, input().split())
h, w = map(int, input().split())

print(H*W - W*h - H*w + h*w)
Buggy python submission (verdict: Runtime Error):
a, b, k = map(int,input().split())
List = []

for i in range(1,101,1):
    if a % i == 0 and b % i == 0:
        List.append(i)

print(List[k-1])

Fixed submission:
a, b, k = map(int,input().split())
List = []

for i in range(1,101,1):
    if a % i == 0 and b % i == 0:
        List.append(i)

print(List[-k])
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import math 
n = np.arange(int(input()))+1

sum = 0
for i in n:
  for j in n:
    for k in n:
      sum += math.gcd(math.gcd(i,j),k)
print(sum)

Fixed submission:
import numpy as np
import math 
n = int(input())

s = np.zeros(3) # *3,*6

s[0] = n*(n+1)//2
for i in np.arange(n)+1:
  for j in np.arange(i+1,n+1):
    s[1] += math.gcd(i,j)
    for k in np.arange(j+1, n+1):
      s[2] += math.gcd(math.gcd(i,j),k)
print(int(sum(s*[1,6,6])))
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

def a():
  n, p = list(map(int, input().split()))
  s = input()
  if(p==2 or p==5):
    count=0
    for i in range(1,n+1):
      if(int(s[-i])%p == 0):
        count += n-i+1
    print(count)
    return

  num = np.array([int(s[i:]) for i in range(n)]) % p
  c = sum(num == 0)
  count = c*(c+1)//2
  for i in range(1,p):
    c = sum(num == i)
    count += c*(c-1)//2
  print(count)
  return
a()

Fixed submission:
import numpy as np

def a():
  n, p = list(map(int, input().split()))
  num = [int(s) for s in input()]
  
  if(p==2 or p==5):
    count=0
    for i in range(1,n+1):
      if(num[-i]%p == 0):
        count += n-i+1
    print(count)
    return
  
  counts = np.zeros(p)
  tmp = 0
  tens = 1
  for i in range(1,n+1):
    tmp = (tens*num[-i] + tmp) % p
    counts[tmp] += 1
    tens = (tens*10)%p
  ret = int(counts[0] + sum(counts*(counts-1)//2))
  print(ret)
  return
a()

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

count = 0
num = 0
for i in range(n):
  m = 0
  for j in range(i, n):
    m = (10*m + int(s[j])) % p
    if(m == 0):
      count += 1
    
print(count)

Fixed submission:
import numpy as np

def a():
  n, p = list(map(int, input().split()))
  num = [int(s) for s in input()]
  
  if(p==2 or p==5):
    count=0
    for i in range(1,n+1):
      if(num[-i]%p == 0):
        count += n-i+1
    print(count)
    return
  
  counts = np.zeros(p)
  tmp = 0
  tens = 1
  for i in range(1,n+1):
    tmp = (tens*num[-i] + tmp) % p
    counts[tmp] += 1
    tens = (tens*10)%p
  ret = int(counts[0] + sum(counts*(counts-1)//2))
  print(ret)
  return
a()

Buggy python submission (verdict: Runtime Error):
n, p = list(map(int, input().split()))
s = input()

count = 0
res = [s[i:j] for i in range(n) for j in range(i+1, n+1)] 

for ss in res:
  if(int(ss) % p == 0):
      count += 1
print(count)

Fixed submission:
import numpy as np

def a():
  n, p = list(map(int, input().split()))
  num = [int(s) for s in input()]
  
  if(p==2 or p==5):
    count=0
    for i in range(1,n+1):
      if(num[-i]%p == 0):
        count += n-i+1
    print(count)
    return
  
  counts = np.zeros(p)
  tmp = 0
  tens = 1
  for i in range(1,n+1):
    tmp = (tens*num[-i] + tmp) % p
    counts[tmp] += 1
    tens = (tens*10)%p
  ret = int(counts[0] + sum(counts*(counts-1)//2))
  print(ret)
  return
a()

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

count = 0
for i in range(n):
  for j in range(n-i):
    if(int(s[i:i+j+1]) % p == 0):
      count += 1
print(count)


Fixed submission:
import numpy as np

def a():
  n, p = list(map(int, input().split()))
  num = [int(s) for s in input()]
  
  if(p==2 or p==5):
    count=0
    for i in range(1,n+1):
      if(num[-i]%p == 0):
        count += n-i+1
    print(count)
    return
  
  counts = np.zeros(p)
  tmp = 0
  tens = 1
  for i in range(1,n+1):
    tmp = (tens*num[-i] + tmp) % p
    counts[tmp] += 1
    tens = (tens*10)%p
  ret = int(counts[0] + sum(counts*(counts-1)//2))
  print(ret)
  return
a()
Buggy python submission (verdict: Runtime Error):
S, T = input().split()
A, B = map(int, input().split())
U = input()
if U == S:    A -= 1
else: B -= 1
print(A,B)

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

Fixed submission:
S = input()
print(''.join(['x' for x in S]))

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

Fixed submission:
S = input()
print(''.join(['x' for x in S]))

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

Fixed submission:
S = input()
print(''.join(['x' for x in S]))
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = str(input())
print(S.count("ABC"))

Fixed submission:
N = int(input())
S = input()
print(S.count("ABC"))