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

Fixed submission:
import sys
read = sys.stdin.buffer.read
readlines = sys.stdin.buffer.readlines
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)


def main():
    OFS = 100005
    N = int(input())
    G = [[] for _ in [0]*OFS*2]
    for line in readlines():
        x, y = map(int, line.split())
        y += OFS
        G[x].append(y)
        G[y].append(x)

    def dfs(v):
        if v < OFS:
            counter[0] += 1
        else:
            counter[1] += 1

        for u in G[v]:
            if visited[u]:
                continue
            visited[u] = 1
            dfs(u)

    visited = [0]*OFS*2
    ans = 0
    for i in range(OFS):
        if visited[i]:
            continue
        counter = [0]*2
        visited[i] = 1
        dfs(i)
        ans += counter[0] * counter[1]

    print(ans - N)


if __name__ == '__main__':
    main()

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

OFS = 100005
N = int(input())
G = [[] for _ in [0]*OFS*2]
for line in readlines():
    x, y = map(int, line.split())
    y += OFS
    G[x].append(y)
    G[y].append(x)

visited = [0]*OFS*2


def dfs(v, x=0, y=0):
    if v < OFS:
        x += 1
    else:
        y += 1

    for u in G[v]:
        if visited[u]:
            continue
        visited[u] = 1
        x, y = dfs(u, x, y)

    return x, y


ans = 0
for i in range(OFS):
    if visited[i]:
        continue
    visited[i] = 1
    x, y = dfs(i)
    ans += x*y

print(ans - N)
Problem p03295 (python)

Fixed submission:
N, M, *A = map(int, open(0).read().split())
*A, = zip(*[iter(A)]*2)
A.sort()
cnt = 0
R = 0
for a, b in A:
    if R <= a:
        cnt += 1
        R = b
    elif b < R:
        R = b
print(cnt)

Buggy submission (verdict: Runtime Error):
import sys
N, M = map(int, input().split())
A = [tuple(map(int, line.split())) for line in sys.stdin.buffer.readlines()]
A.sort()
cnt = 0
R = 0
for a, b in A:
    if R <= a:
        cnt += 1
        R = b
    elif b < R:
        R = b
print(cnt)
Problem p03805 (python)

Fixed submission:
n, m = map(int, input().split())
G = [[] for _ in range(n)]

for i in range(m):
    a, b = map(int, input().split())
    a-=1; b-=1
    G[a].append(b)
    G[b].append(a)

flag = (1<<n)-1

def dfs(v=0, visited=1):
    if visited == flag:
        return 1

    cnt = 0
    for to in G[v]:
        if visited & (1<<to):
            continue
        cnt += dfs(to, visited^(1<<to))
    return cnt

print(dfs())

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
G = [[] for _ in range(n)]

for i in range(n):
    a, b = map(int, input().split())
    a-=1; b-=1
    G[a].append(b)
    G[b].append(a)

flag = (1<<n)-1

def dfs(v=0, visited=1):
    if visited == flag:
        return 1

    cnt = 0
    for to in G[v]:
        if visited & 1<<to:
            continue
        cnt += dfs(to, visited^(1<<to))
    return cnt

print(dfs())

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
G = [[] for _ in range(n)]

for i in range(n):
    a, b = map(int, input().split())
    a-=1; b-=1
    G[a].append(b)
    G[b].append(a)

flag = (1<<n)-1

def dfs(v=0, visited=1):
    if visited == flag:
        return 1

    cnt = 0
    for to in G[v]:
        if visited & 1<<to:
            continue
        cnt += dfs(to, visited^(1<<to))
    return cnt

print(dfs())
Problem p02580 (python)

Fixed submission:
import sys
from collections import Counter
input = lambda : sys.stdin.readline().rstrip()

h, w, m = map(int, input().split(" "))

xs = []
ys = []
for i in range(m):
    x, y = map(int, input().split(" "))
    xs.append(x)
    ys.append(y)

xcounter = Counter(xs)
ycounter = Counter(ys)

x_most, x_most_num = xcounter.most_common(1)[0]
#y_most, y_most_num = ycounter.most_common(1)[0]

#if x_most_num < y_most_num:
#    x_most_num = y_most_num
#    tmp = ys
#    ys = xs
#    xs = tmp
#
out1 = x_most_num

if x_most_num < m:
    y2s = [] 
    for i in range(m):
        if xs[i] == x_most:
            continue
        else:  
            y2s.append(ys[i])
        
    y2counter = Counter(y2s)
    y2_most, y2_most_num = y2counter.most_common(1)[0]
    out1 += y2_most_num


y_most, y_most_num = ycounter.most_common(1)[0]

out2 = y_most_num

if y_most_num < m:
    x2s = [] 
    for i in range(m):
        if ys[i] == y_most:
            continue
        else:  
            x2s.append(xs[i])
        
    x2counter = Counter(x2s)
    x2_most, x2_most_num = x2counter.most_common(1)[0]
    out2 += x2_most_num

out = max(out1, out2)

print(out)

Buggy submission (verdict: Runtime Error):
import sys
from collections import Counter
input = lambda : sys.stdin.readline().rstrip()

h, w, m = map(int, input().split(" "))

xs = []
ys = []
for i in range(m):
    x, y = map(int, input().split(" "))
    xs.append(x)
    ys.append(y)

xcounter = Counter(xs)
ycounter = Counter(ys)

x_most, x_most_num = xcounter.most_common(1)[0]
y_most, y_most_num = ycounter.most_common(1)[0]

out = 0
if x_most_num < y_most_num:
    #swap
    x_most_num = y_most_num
    tmp = ys
    ys = xs
    xs = tmp


out = x_most_num

y2s = [] 
for i in range(m):
    if xs[i] == x_most:
        continue
    else:  
        y2s.append(ys[i])
    

y2counter = Counter(y2s)
y2_most, y2_most_num = y2counter.most_common(1)[0]
out += y2_most_num

print(out)
Problem p02629 (python)

Fixed submission:
from math import log, ceil
r = 26
ab = "abcdefghijklmnopqrstuvwxyz"
input = raw_input
n = int(input())

def answer(n):
    m = int(ceil(log(n*(r-1) + r, r))) - 1

    #cur = r ** (m-1)
    out = ""

    sub = (r ** m - r) // (r-1)
    n = n - sub - 1
    for i in range(m):
        i = n % r
        out = ab[i] + out
        n //= r
        #i = n // cur
        #out = out + ab[i-1]
        #n -= i * cur
        #cur //= r
    return out

#for n in range(1, 676 + 26 + 2):
if True:
    out = answer(n)
    #print(n, out)
    print(out)

Buggy submission (verdict: Runtime Error):
from math import log, ceil
r = 26
ab = "abcdefghijklmnopqrstuvwxyz"
input = raw_input
n = int(input())

def answer(n):
    m = int(ceil(log(n*(r-1) + r, r))) - 1

    cur = r ** (m-1)
    out = ""
    for i in range(m):
        i = n // cur
        out = out + ab[i-1]
        n -= i * cur
        cur //= r
    return out

out = answer(n)
print(out)

Buggy submission (verdict: Runtime Error):
from math import log, ceil
r = 26
ab = "abcdefghijklmnopqrstuvwxyz"
input = raw_input
n = int(input())
m = int(ceil(log(n*(r-1) + r, r) - 1))

uhen = r ** m
sahen = n * (r-1) + r
if sahen < uhen:
    m -= 1
else:
    uhen *= r
    if sahen > uhen:
        m += 1
    else:
        pass

cur = r ** (m-1)
out = ""
for i in range(m):
    i = n // cur
    out = out + ab[i-1]
    n -= i * cur
    cur //= r


print(out)
Problem p02873 (python)

Fixed submission:
input = raw_input
S = input()
n = len(S) # N-1
s = S


up_count = 0
down_count = 0

start_i = None
for i, c in enumerate(S):
    if c == "<":
        start_i = i
        break
    down_count += 1

if start_i is None:
    start_i = n

nums = []
for num in reversed(range(down_count+1)):
    nums.append(num)

up = True
for c in S[start_i:]: 
    if c == "<":
        if not up: # down->up
            if up_count >= down_count:
                for num in range(1, up_count+1):
                    nums.append(num)
                for num in reversed(range(0, down_count)):
                    nums.append(num)
            else:
                for num in range(0, up_count):
                    nums.append(num)
                for num in reversed(range(1, down_count+1)):
                    nums.append(num)
                 
            down_count = 0
            up_count = 1
            up = True
        else:
            up_count += 1
    else:
        if up:
            up = False
            down_count = 1
        else:
            down_count += 1
        

if up:
    for num in range(up_count+1):
        nums.append(num)
else:
    if up_count >= down_count:
        for num in range(1, up_count+1):
            nums.append(num)
        for num in reversed(range(0, down_count)):
            nums.append(num)
    else:
        for num in range(0, up_count):
            nums.append(num)
        for num in reversed(range(1, down_count+1)):
            nums.append(num)

out = sum(nums)
print(out)

Buggy submission (verdict: Runtime Error):
input = raw_input
S = input()
n = len(S) # N-1
s = S


up_count = 0
down_count = 0

for i, c in enumerate(S):
    if c == "<":
        start_i = i
        break
    down_count += 1

nums = []
for num in reversed(range(down_count+1)):
    nums.append(num)

up = True
for c in S[start_i:]: 
    if c == "<":
        if not up: # down->up
            if up_count >= down_count:
                for num in range(1, up_count+1):
                    nums.append(num)
                for num in reversed(range(0, down_count)):
                    nums.append(num)
            else:
                for num in range(0, up_count):
                    nums.append(num)
                for num in reversed(range(1, down_count+1)):
                    nums.append(num)
                 
            down_count = 0
            up_count = 1
            up = True
        else:
            up_count += 1
    else:
        if up:
            up = False
            down_count = 1
        else:
            down_count += 1
        

if up:
    for num in range(up_count+1):
        nums.append(num)
else:
    if up_count >= down_count:
        for num in range(1, up_count+1):
            nums.append(num)
        for num in reversed(range(0, down_count)):
            nums.append(num)
    else:
        for num in range(0, up_count):
            nums.append(num)
        for num in reversed(range(1, down_count+1)):
            nums.append(num)

out = sum(nums)
print(out)
Problem p02948 (python)

Fixed submission:
#input = raw_input
#import numpy as np

from heapq import heappush, heappop

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

values = [[] for i in range(M+1)]
for i in range(N):
    A, B = map(int, input().split())
    if M >= A:
        values[A].append(-B)

#print(values)
out = 0
elms = []
for i in range(1, M+1):
    #print("values[i]", values[i])
    for elm in values[i]:
        heappush(elms, elm)
        
    if len(elms) >= 1:
        max_val = - heappop(elms)
        #print("mval", max_val)
        out += max_val

print(out)

Buggy submission (verdict: Runtime Error):
#input = raw_input
import numpy as np

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

pairs = []
for i in range(N):
    A, B = map(int, input().split())
    if M >= A:
        pairs.append([A, B])

pairs = sorted(pairs, key=lambda elm: -elm[1])
#print(pairs)

out = 0

#not_done = [True for _ in range(M)]

#counts = [0 for _ in range(M)]
cumsum_counts = np.zeros(M, dtype=int)

all_sum = 0

ue_end_i = M-1
for A, B in pairs:
    ue_start_i = M-A+1
    if ue_start_i <= ue_end_i:
        ue_limit = ue_end_i - ue_start_i + 1
        #ue_sum = sum(counts[ue_start_i:])
        ue_sum = cumsum_counts[ue_start_i]
        hamidashi = max(ue_sum - ue_limit, 0)
    else:
        # ue_start_i == M
        hamidashi = 0
    #print("hamidashi", hamidashi)

    cur_limit = M- A + 1 - hamidashi # 0 ~ M-A
    sudeni = all_sum - ue_sum
    aki = cur_limit - sudeni

    if aki >= 1:
        out += B
        #counts[M-A] += 1
        cumsum_counts[M-A:] += 1
        all_sum += 1

print(out)

Buggy submission (verdict: Runtime Error):
#input = raw_input
import numpy as np

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

pairs = []
for i in range(N):
    pairs.append(list(map(int, input().split())))

pairs = sorted(pairs, key=lambda elm: -elm[1])
#print(pairs)

finish_day = -1
out = 0

#not_done = [True for _ in range(M)]

counts = [0 for _ in range(M)]
cumsum_counts = np.zeros(0, dtype=int)

all_sum = 0

ue_end_i = M-1
for A, B in pairs:
    if A > M:
        continue
    ue_start_i = M-A+1
    if ue_start_i <= ue_end_i:
        ue_limit = ue_end_i - ue_start_i + 1
        #ue_sum = sum(counts[ue_start_i:])
        ue_sum = cumsum(ue_start_i)
        hamidashi = max(ue_sum - ue_limit, 0)
    else:
        # ue_start_i == M
        ue_sum = 0
        hamidashi = 0
    #print("hamidashi", hamidashi)

    cur_limit = M- A + 1 - hamidashi # 0 ~ M-A
    sudeni = all_sum - ue_sum
    aki = cur_limit - sudeni

    if aki >= 1:
        out += B
        #counts[M-A] += 1
        cumsum_counts[M-A:] += 1
        all_sum += 1

print(out)

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

pairs = []
for i in range(N):
    pairs.append(list(map(int, input().split())))

pairs = sorted(pairs, key=lambda elm: [-elm[1], -elm[0]] )
#print(pairs)

finish_day = -1
out = 0

not_done = [True for _ in range(N)]

for A, B in pairs:
    for i in range(M-A, -1, -1):
        if not_done[i]:
            out += B
            #print(A, B)
            not_done[i] = False
            break

print(out)
Problem p03272 (python)

Fixed submission:
inputs = raw_input().replace("\n", "")
N, i = map(int, inputs.split(" "))
print N + 1 - i

Buggy submission (verdict: Runtime Error):
import numpy as np

H, W = map(int, input().split(" "))

lines = np.asarray([list(input().replace("\n", "")) for h in range(H)])

h_indexs, w_indexs = map(set, np.where(lines == "#"))

outlines = lines[list(h_indexs), :][:, list(w_indexs)]
for outline in outlines:
    print("".join(outline))
Problem p02884 (python)

Fixed submission:
import sys

def input():
    return sys.stdin.readline()[:-1]

def main():
    N,M = list(map(int,input().split()))

    e_list = [[] for i in range(N)]

    for i in range(M):
        s,t = list(map(int,input().split()))
        s,t = s-1,t-1
        e_list[s].append(t)

    DP = [0]*N
    dp0_min = 10**27

    for x in range(N-1):
        for i in range(N-1):
            if i==x:
                if len(e_list[N-i-2])==1:
                    DP[N-i-2] = DP[e_list[N-i-2][0]]+1
                else:
                    max_room = -1
                    max_path = 0
                    for j in e_list[N-i-2]:
                        if max_path<DP[j]:
                            max_room = j
                            max_path = DP[j]
                        DP[N-i-2] += DP[j]
                    DP[N-i-2] -= DP[max_room]
                    DP[N-i-2] /= len(e_list[N-i-2])-1
                    DP[N-i-2] += 1
            else:
                for j in e_list[N-i-2]:
                    DP[N-i-2] += DP[j]
                DP[N-i-2] /= len(e_list[N-i-2])
                DP[N-i-2] += 1
        dp0_min = min(dp0_min,DP[0])
        DP = [0]*N
    print(dp0_min)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):

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

e_list = [[] for i in range(N)]

for i in range(M):
    s,t = list(map(int,input().split()))
    s,t = s-1,t-1
    e_list[s].append(t)

DP = [[0] for i in range(N)]
dp0_min = 10**27

for x in range(N-1):
    for i in range(N-1):
        if i==x:
            if len(e_list[N-i-2])==1:
                DP[N-i-2] = DP[e_list[N-i-2][0]]+1
            else:
                max_room = -1
                max_path = 0
                for j in e_list[N-i-2]:
                    if max_path<DP[j]:
                        max_room = j
                        max_path = DP[j]
                    DP[N-i-2] += DP[j]
                DP[N-i-2] -= DP[max_room]
                DP[N-i-2] /= len(e_list[N-i-2])-1
                DP[N-i-2] += 1
        else:
            for j in e_list[N-i-2]:
                DP[N-i-2] += DP[j]
            DP[N-i-2] /= len(e_list[N-i-2])
            DP[N-i-2] += 1
    dp0_min = min(dp0_min,DP[0])
    DP = [[0] for i in range(N)]
print(dp0_min)

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

A.sort()
F.sort(reverse = True)

M = 0
for i in range(N):
    M=max(F[i]*A[i],M)

def judge(n):
    score = 0
    for i in range(N):
        score += max(A[i] - n//F[i],0)
    return score<=K

def bisect(l,r):
    while r-l>1:
        if judge((l+r)//2):
            r = (l+r)//2
        else:
            l = (l+r)//2
    return r

if judge(0):
    print(0)
else:
    print(bisect(0,M))
Problem p02987 (python)

Fixed submission:
S=input()

from collections import Counter

c=Counter([S[0],S[1],S[2],S[3]])

if len(list(c.keys()))==2:
    flag=True
    for key in c.keys():
        if c[key]!=2:
            flag=False
            break

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

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

from collections import Counter

c=Counter([S[0],S[1],S[2],S[3]])

if len(list(c.keys()))==2:
    flag=True
    for key in c.keys():
        if c[key]!=2:
            flag=False:
            break

    if flag:
        print("Yes")
    else:
        print("No")
else:
    print("No")
Problem p03222 (python)

Fixed submission:
H,W,K = list(map(int,input().split()))


amida = [0 for i in range(8)]
amida[0]=1
amida[1]=2
amida[2]=3
amida[3]=5
amida[4]=8
amida[5]=13
amida[6]=21
amida[7]=34

def amida_num(k,l):
    return amida[max(k,0)]*amida[max(l,0)]


dp=[[0 for i in range(W)] for j in range(H+1)]

dp[0][0] = 1

if W!=1:
    for i in range(1,H+1):
        for j in range(W):
            if j==0:
                dp[i][j]=dp[i-1][j+1]*amida_num(0,W-3) + dp[i-1][j]* amida_num(0,W-2)
            elif j==W-1:
                dp[i][j]=dp[i-1][j-1]*amida_num(0,W-3) + dp[i-1][j]* amida_num(0,W-2)
            else:
                dp[i][j]=dp[i-1][j-1]*amida_num(j-2,W-j-2) + dp[i-1][j]*amida_num(j-1,W-j-2) + dp[i-1][j+1]*amida_num(j-1,W-j-3)
    print(dp[H][K-1]%(10**9+7))
else:
    print(1)

Buggy submission (verdict: Runtime Error):

H,W,K = list(map(int,input().split()))


amida = [0 for i in range(8)]
amida[0]=1
amida[1]=2
amida[2]=3
amida[3]=5
amida[4]=8
amida[5]=13
amida[6]=21
amida[7]=34

def amida_num(k,l):
    return amida[max(k,0)]*amida[max(l,0)]


dp=[[0 for i in range(W)] for j in range(H+1)]

dp[0][0] = 1

for i in range(1,H+1):
    for j in range(W):
        if j==0:
            dp[i][j]=dp[i-1][j+1]*amida_num(0,W-3) + dp[i-1][j]* amida_num(0,W-2)
        elif j==W-1:
            dp[i][j]=dp[i-1][j-1]*amida_num(0,W-3) + dp[i-1][j]* amida_num(0,W-2)
        else:
            dp[i][j]=dp[i-1][j-1]*amida_num(j-2,W-j-2) + dp[i-1][j]*amida_num(j-1,W-j-2) + dp[i-1][j+1]*amida_num(j-1,W-j-3)

print(dp[H][K-1]%(10**9+7))
Problem p03250 (python)

Fixed submission:
L=map(int,raw_input().split())

m = max(L)
i = L.index(m)
score=m*10
for j in range(3):
    if j!=i:
        score+=L[j]
print score

Buggy submission (verdict: Runtime Error):
L=map(int,raw_input().split())

m = max(L)
i = L.index(L)
score=m*10
for j in range(3):
    if j!=i:
        score+=L[j]
print score
Problem p03272 (python)

Fixed submission:
N,i= map(int,raw_input().split())

print N-i+1

Buggy submission (verdict: Runtime Error):
H,W= map(int,raw_input().split())

M = []
for i in range(H):
	M.append(raw_input())
	
flag_list_H = []
for i in range(H):
	if '#' in M[i]:
		flag_list_H.append(True)
	else:
		flag_list_H.append(False)

flag_list_W = []
for i in range(W):
	flag = False
	for j in range(H):
		if M[j][i]=='#':
			flag=True
	flag_list_W.append(flag)

for i in range(H):
	answer = ""
	for j in range(W):
		if flag_list_H[i] and flag_list_W[j]:
			answer+=M[i][j] + " "
	print answer[:-1]
Problem p03345 (python)

Fixed submission:
a,b,c,k = map(int,raw_input().split())

if k%2==0:
	print a-b
else:
	print b-a

Buggy submission (verdict: Runtime Error):
a,b,c,k = map(int,raw_input())

if k%2==0:
	print a-b
else:
	print b-a

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

if k%2==0:
	print a-b
else:
	print b-a
Problem p03346 (python)

Fixed submission:
N = int(raw_input())
P = []
for i in range(N):
	P.append(int(raw_input()))

Q = range(N)

for i in range(N):
	Q[P[i]-1] = i+1

count = 0
max = 0
for i in range(N-1):
	if Q[i]<Q[i+1]:
		count+=1
	else:
		count=0
	
	if max < count:
		max = count

print N-max-1

Buggy submission (verdict: Runtime Error):
in = raw_input().split()
N = in[0]
P = in[1:]

Q = range(N)

for i in range(N):
	Q[P[i]-1] = i+1

count = 0
max = 0
for i in range(N-1):
	if Q[i]<Q[i+1]:
		count+=1
	else:
		count=0
	
	if max < count:
		max = count

print N-count-1
Problem p04021 (python)

Fixed submission:
N=int(input())
A=[]
for i in range(N):
    A.append(int(input()))

B=sorted(A)

C=[]
D=[]

for i in range(N):
    if i%2==0:
        C.append(A[i])
        D.append(B[i])
        
print((N+1)//2-len(set(C) & set(D)))

Buggy submission (verdict: Runtime Error):


def nibutan2(array,value,left,right,first = True):
    if first:
        if array[left]>value:
            return 0
        elif array[right]<value:
            return len(array)
    if right-left<=1:
        return right
    else:
        i=(left+right)//2
        if array[i]>value:
            return nibutan2(array,value,left,i,False)
        elif array[i]<value:
            return nibutan2(array,value,i,right,False)


N=int(input())
A=[]
B=[]
for i in range(N):
    if i%2==0:
        A.append(int(input()))
    else:
        B.append(int(input()))

A.sort()
B.sort()

count=0

for i in range(len(A)):
    c=nibutan2(B,A[i],0,len(B)-1)
    count+=abs(c-i)

print(count)

Buggy submission (verdict: Runtime Error):
def nibutan2(array,value,left,right,first = True):
    if first:
        if array[left]>value:
            return 0
        elif array[right]<value:
            return len(array)
    if right-left<=1:
        return right
    else:
        i=(left+right)//2
        if array[i]>value:
            return nibutan(array,value,left,i,False)
        elif array[i]<value:
            return nibutan(array,value,i,right,False)


N=int(input())
A=[]
B=[]
for i in range(N):
    if i%2==0:
        A.append(int(input()))
    else:
        B.append(int(input()))

A.sort()
B.sort()

count=0

for i in range(len(A)):
    c=nibutan2(B,A[i],0,len(B)-1)
    count+=abs(c-i)

print(count)
Problem p02552 (python)

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

Buggy submission (verdict: Runtime Error):
print(0 if input()='1' else 1)
Problem p02757 (python)

Fixed submission:
n,p=map(int,input().split())
s=input()
ans=0
if p==2 or p==5:
    for i in range(n):
        if int(s[i])%p==0:
            ans+=i+1
else:
    M=[0]*p
    M[0]=1
    tmp=0
    for i in range(n):
        tmp+=(int(s[-i-1])*pow(10,i,p))
        tmp%=p
        ans+=M[tmp]
        M[tmp]+=1
print(ans)

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

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

Buggy submission (verdict: Runtime Error):
n,p=map(int,input().split())
s=input()[::-1]
A=[0]*n
D=[0]*n
M=[0]*n
ans=0
if p==2 or p==5:
    for i in range(n):
        if int(s[i])%p==0:
            ans+=i+1
else:
    for i in range(n):
        tmp=int(s[i])*10**i
        A[i]=tmp%p
    D[0]=A[0]
    M[D[0]]+=1
    for i in range(1,n):
        D[i]=(D[i-1]+A[i])%p
        M[D[i]]+=1
        ans+=(M[D[i]]-1)
    ans+=D.count(0)
print(ans)
Problem p02766 (python)

Fixed submission:
def convert(n, k):
    if (int(n/k)):
        return convert(int(n/k), k)+str(n%k)
    return str(n%k)
n,k=map(int,input().split())
print(len(convert(n,k)))

Buggy submission (verdict: Runtime Error):
def convert(n, k):
    if (int(n/k)):
        return convert(int(n/k), k)+str(n%k)
    return str(n%k)
n,k=map(int,input().split())
print(len(Base_10_to_n(n,k)))
Problem p02897 (python)

Fixed submission:
n=int(input())
print((-(-n//2))/n)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
ans=[i for i in range(n)]
for i in range(n):
    ans[i]=a.index(i+1)+1
print(*ans)