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

H, W = map(int, input().split())
M = []
for h in range(H):
    col = []
    s = input()
    for w in range(W):
        if s[w] == '.':
            col.append(0)
        else:
            col.append(np.inf)
    M.append(col)



for h in range(H):
    for w in range(W):
        flag_h0= True
        flag_hM = True
        flag_w0 = True
        flag_wM = True
        if M[h][w] == np.inf:
            
            if h==0:
                flag_h0= False
            if h == H - 1:
                flag_hM = False
            if w== 0:
                flag_w0 = False
            if w== W-1:
                flag_wM = False
            
            if flag_h0:
                M[h-1][w] += 1
                if  flag_w0:
                    M[h-1][w-1] += 1
                if flag_wM:
                    M[h-1][w+1] += 1
            
            if flag_w0:
                M[h][w-1] += 1
            if flag_wM:
                M[h][w+1] += 1
            
            if flag_hM:
                M[h+1][w] += 1

                if flag_w0:
                    M[h+1][w-1] += 1
                if flag_wM:
                    M[h+1][w+1] += 1

                    
for h in range(H):
    tmp_ = ''
    for w in range(W):
        if M[h][w] < np.inf:
            tmp_ += str(M[h][w])
        else:
            tmp_  += '#'
    print(tmp_)
                

Fixed submission:


import numpy as np
H, W = map(int, input().split())
M = []
for h in range(H):
    col = []
    s = input()
    for w in range(W):
        if s[w] == '.':
            col.append(0)
        else:
            col.append(np.inf)
    M.append(col)



for h in range(H):
    for w in range(W):
        flag_h0= True
        flag_hM = True
        flag_w0 = True
        flag_wM = True
        if M[h][w] == np.inf:
            
            if h==0:
                flag_h0= False
            if h == H - 1:
                flag_hM = False
            if w== 0:
                flag_w0 = False
            if w== W-1:
                flag_wM = False
            
            if flag_h0:
                M[h-1][w] += 1
                if  flag_w0:
                    M[h-1][w-1] += 1
                if flag_wM:
                    M[h-1][w+1] += 1
            
            if flag_w0:
                M[h][w-1] += 1
            if flag_wM:
                M[h][w+1] += 1
            
            if flag_hM:
                M[h+1][w] += 1

                if flag_w0:
                    M[h+1][w-1] += 1
                if flag_wM:
                    M[h+1][w+1] += 1

                    
for h in range(H):
    tmp_ = ''
    for w in range(W):
        if M[h][w] < np.inf:
            tmp_ += str(M[h][w])
        else:
            tmp_  += '#'
    print(tmp_)
Buggy python submission (verdict: Runtime Error):
IN = iter(Input.split('\n')).__next__
def input():
    return IN()

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

result_list = []
for a in l:
    result_list.extend([a-1,a,a+1])
    
result_list

import collections

count = collections.Counter(result_list) # dictionary としてCounter({5: 1, 1: 3, 3: 2, 2: 2, 4: 2})
hindo_jun = count.most_common() 

print(hindo_jun[0][1])

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

result_list = []
for a in l:
    result_list.extend([a-1,a,a+1])
    
result_list

import collections

count = collections.Counter(result_list) # dictionary としてCounter({5: 1, 1: 3, 3: 2, 2: 2, 4: 2})
hindo_jun = count.most_common() 

print(hindo_jun[0][1])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = input().split()
i = 0
S = 1
for i in range(N):
    S *= int(A[i])
if S > 10**18:
    print(-1)
else:
    print(S)


Fixed submission:
N = int(input())
A = input().split()
S = 1
if "0" in A:
    print(0)
else:
    for i in range(N):
        S *= int(A[i])
        if S > 10**18:
            break
    if S > 10**18:
        print(-1)
    else:
        print(S)
Buggy python submission (verdict: Runtime Error):
import math
A,B = input().split()

if (float(B) - (int(float(B)))) * 100 * 100 == 28.99999999999999:
    D = 29 + int(float(B)) * 100
elif (float(B) - (int(float(B)))) * 100 * 100 == 57.99999999999999:
    D = 58 + int(float(B)) * 100
else:
    D = int(float(B) * 100)

C = math.floor(int(A) * int(B) / 100)
print(C)


Fixed submission:
A,B = input().split()
B = B[:-3] + B[-2:]
C = int(A) * int(B) // 100
print(C)
Buggy python submission (verdict: Runtime Error):
X = int(input())

B = 0
while B > -10**9:
    A = X + B**5
    if pow(A,0.2) - int(pow(A,0.2)) == 0:
        print(int(pow(A,0.2)), B)
        break
    B -= 1
if pow(A,0.2) - int(pow(A,0.2)) != 0:
    B = 0
    while B < 10**9:
        A = X + B**5
        if pow(A,0.2) - int(pow(A,0.2)) == 0:
            print(int(pow(A,0.2)), B)
            break
        B += 1


Fixed submission:
X = int(input())
A = 0
B = 0
for i in range(-118,119,1):
    for j in range(-119,118,1):
        if i**5 - j**5 == X:
            print(i, j)
            break
    else:
        continue
    break
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
N,K = map(int,input().split())
A = list()
B = list()
x = 0
A = [2**100+i for i in range(N+1)]
for i in range(K, N+2):
    a = itertools.combinations(A,i)
    for s in a:
        B.append(sum(s))
print(len(list(set(B)))%(10**9+7))


Fixed submission:
N,K = map(int,input().split())
sum = 0
for i in range(K, N+2):
    sum += i * (N - i + 1) + 1
print(sum % (10**9+7))
Buggy python submission (verdict: Time Limit Exceeded):
def gcd(x,y):
    if y == 0:
        return x
    return gcd(y, x%y)


K = int(input())
sum = 0
for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            A = gcd(a,b)
            B = gcd(A,c)
            sum += B
print(sum)


Fixed submission:
def gcd(x,y):
    if y == 0:
        return x
    return gcd(y, x%y)

K = int(input())
sum = 0
for a in range(1,K-1):
    for b in range(a+1,K):
        for c in range(b+1,K+1):
            sum += gcd(gcd(a,b),c) * 6

for a in range(1,K+1):
    for b in range(1,K+1):
        sum += gcd(gcd(a,b),b) * 3

for i in range(1,K+1):
    sum -=2*i
    
print(sum)
Buggy python submission (verdict: Runtime Error):
S=input()
if S[3] == S[4]:
    if S[5] == S[6]:
        print("Yes")
    else:
        print("No")
else:
    print("No")    


Fixed submission:
S=input()
if S[2] == S[3]:
    if S[4] == S[5]:
        print("Yes")
    else:
        print("No")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
N=int(input())
S=list()
Y=list()
for i in range(N):
    S.append(input())
X=Counter(S)
Y.append(X.most_common()[0][0])
for i in range(len(X)-1):
    if X.most_common()[i][1] == X.most_common()[i+1][1]:
        Y.append(X.most_common()[i+1][0])
    else:
        break
Y.sort()
for i in range(len(Y)):
    print(Y[i])


Fixed submission:
from collections import Counter
N=int(input())
S=list()
Y=list()
for i in range(N):
    S.append(input())
X=Counter(S)
F=X.most_common()[0][1]
keys = [k for k, v in X.items() if v == F]
keys.sort()
for i in range(len(keys)):
    print(keys[i])
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()
count = 0
for i in range(N):
    if S[i] == "A":
        if S[i+1] == "B":
            if S[i+2] == "C":
                count += 1
print(count)


Fixed submission:
N = int(input())
S = input()
count = 0
for i in range(N - 2):
    if S[i] == "A":
        if S[i+1] == "B":
            if S[i+2] == "C":
                count += 1
print(count)
Buggy python submission (verdict: Runtime Error):
import math
A,B = map(int,input().split())
lcm = A * B // math.gcd(A,B)
print(lcm)


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

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

lcm = A * B // gcd(A,B)
print(lcm)

Buggy python submission (verdict: Runtime Error):
import math
A,B = map(int,input().split())
print(int(A * B / math.gcd(A,B)))


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

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

lcm = A * B // gcd(A,B)
print(lcm)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

for i in range(1,N+1):
    ans = 0

    for x in range(1,101):
        if x**2>i:
            break
        for y in range(1,101):
            if x**2+y**2>i:
                break
            for z in range(1,101):
                if x**2+y**2+z**2+x*y+y*z+z*x==i:
                    ans += 1
                
    print(ans)

Fixed submission:
N = int(input())

for i in range(1,N+1):
    ans1 = 0
    ans2 = 0
    ans3 = 0
    
    for x in range(1,101):
        if x**2>i:
            break
        for y in range(1,x):
            if x**2+y**2+x*y>i:
                break
            for z in range(1,y):
                if x**2+y**2+z**2+x*y+y*z+z*x==i:
                    ans1 += 1

                if x**2+y**2+z**2+x*y+y*z+z*x>i:
                    break

    for x in range(1,101):
        if x**2>i:
            break
        for y in range(1,x):
            if x**2+y**2>i:
                break
            if x**2+3*y**2+2*x*y==i:
                ans2 += 1
    
    for x in range(1,101):
        if x**2>i:
            break
        for y in range(1,x):
            if x**2+y**2>i:
                break
            if 3*x**2+y**2+2*x*y==i:
                ans2 += 1
                
    for x in range(1,101):
        if 6*x**2==i:
            ans3+=1

    print(ans1*6+ans2*3+ans3)
Buggy python submission (verdict: Runtime Error):
a = int(inut())

print(a**3+a**2+a)

Fixed submission:
a = int(input())

print(a**3+a**2+a)
Buggy python submission (verdict: Runtime Error):
S = list(input())
T = list(input())

ans = 0

for i in range(len(S)):
  ans += (S[i]=T[i])

print(ans)

Fixed submission:
S = list(input())
T = list(input())

ans = 0

for i in range(len(S)):
  ans += (S[i]!=T[i])

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

def f(x):
    return int(A*x/B)-A*int(x/B)

X = N
Y = min(B-1,N)

print(min(f(X),f(Y))

Fixed submission:
a, b, n = map(int, input().split())
x = min(b-1, n)
ans = int((a*x)/b) - a*int(x/b)
print(ans)

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

lo = 1
hi = N

def f(x):
    return int(A*x/B)-A*int(x/B)

ans = 0
if B-1<=N:
    ans = f(B-1)

while hi > lo :
    if f(lo) <= f(hi):
        mid = (lo + hi) // 2
        if f(mid)<=f(mid+1):
            lo = mid+1
        else:
            lo = mid
    else:
        mid = -(-(lo + hi) // 2)
        hi = mid

ans = max(ans,f(lo),f(N-1),f(B*N//B-1)+1

print(ans)

Fixed submission:
a, b, n = map(int, input().split())
x = min(b-1, n)
ans = int((a*x)/b) - a*int(x/b)
print(ans)

Buggy python submission (verdict: Runtime Error):
from decimal import Decimal, getcontext

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

lo = 1
hi = N

def f(x):
    return int(Demical(A)*Demical(x)/Demical(B))-A*int(Demical(x)/Demical(B))

ans = 0
if B-1<=N:
    ans = f(B-1)

while hi > lo :
    if f(lo) <= f(hi):
        mid = (lo + hi) // 2
        if f(mid)<=f(mid+1):
            lo = mid+1
        else:
            lo = mid
    else:
        mid = -(-(lo + hi) // 2)
        hi = mid

ans = max(ans,f(lo),f(N-1),f(B*N//B-1))

print(ans)


Fixed submission:
a, b, n = map(int, input().split())
x = min(b-1, n)
ans = int((a*x)/b) - a*int(x/b)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S = list(map(int,list(input())))

MOD = 2019
S.reverse()
cnt = 0
temp = 0
ans = [0]*2019
for i in S:
    temp += i*10**cnt % MOD
    temp %= MOD
    ans[temp] += 1
    cnt += 1

ans[0] += 1

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

Fixed submission:
S = list(input())

MOD = 2019
S.reverse()
cnt = 1
temp = 0
ans = [0]*2019
for i in S:
    temp += int(i)*cnt % MOD
    temp %= MOD
    ans[temp] += 1
    cnt *= 10
    cnt %= MOD

ans[0] += 1

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

Buggy python submission (verdict: Time Limit Exceeded):
S = list(map(int,list(input())))

MOD = 2019
T = []
S.reverse()
cnt = 0
temp = 0
for i in S:
    temp += i*10**cnt % MOD
    temp %= MOD
    T.append(temp)
    cnt += 1

T.reverse()
T.append(0)

ans = [0]*2019

for i in T:
    ans[i-1] += 1

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

Fixed submission:
S = list(input())

MOD = 2019
S.reverse()
cnt = 1
temp = 0
ans = [0]*2019
for i in S:
    temp += int(i)*cnt % MOD
    temp %= MOD
    ans[temp] += 1
    cnt *= 10
    cnt %= MOD

ans[0] += 1

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

Buggy python submission (verdict: Time Limit Exceeded):
S = list(map(int,list(input())))

MOD = 2019
T = []
S.reverse()
cnt = 0
temp = 0
for i in S:
    temp += i*10**cnt % MOD
    temp %= MOD
    T.append(temp)
    cnt += 1

T.reverse()
T.append(0)

ans = [0]*2019

for i in T:
    ans[i-1] += 1

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

Fixed submission:
S = list(input())

MOD = 2019
S.reverse()
cnt = 1
temp = 0
ans = [0]*2019
for i in S:
    temp += int(i)*cnt % MOD
    temp %= MOD
    ans[temp] += 1
    cnt *= 10
    cnt %= MOD

ans[0] += 1

ans2 = 0
for i in ans:
    ans2 += i*(i-1)//2
print(ans2)
Buggy python submission (verdict: Time Limit Exceeded):
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

K = int(input())
ans = 0

for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            ans += gcd(i,j,k)
            
print(ans)

Fixed submission:
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

K = int(input())
ans = 0

for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            ans += gcd(i,j,k)
            
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = list(input())
R = [0]*N
G = [0]*N
B = [0]*N
for i in range(N):
    if S[i]=="R":
        R[i] += 1
    elif S[i] == "G":
        G[i] += 1
    else:
        B[i] += 1

ans = sum(R)*sum(G)*sum(B)

for i in range(N):
    for j in range(i+1,N):
        k = 2*(j+1)-(i+1)-1
        if  k<N:
            if S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
                ans -= 1
                
print(ans)

Fixed submission:
N = int(input())
S = list(input())
R = [0]*N
G = [0]*N
B = [0]*N
for i in range(N):
    if S[i]=="R":
        R[i] += 1
    elif S[i] == "G":
        G[i] += 1
    else:
        B[i] += 1

ans = sum(R)*sum(G)*sum(B)

for i in range(N):
    for j in range(i+1,N):
        k = 2*(j+1)-(i+1)-1
        if  k<N:
            if S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
                ans -= 1
                
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,X,Y = map(int, input().split())

dist = [[0 for i in range(N)] for j in range(N)]
for i in range(1,N):
    for j in range(i):
        dist[i][j]=i-j
dist[Y-1][X-1]=1

for i in range(N):
    y1 = min(Y-1+i,N-1)
    y2 = max(Y-1-i,0)
    for j in range(N):
        x1 = min(X-1+j,N-1)
        x2 = max(X-1-j,0)
        dist[min(y1+1,N-1)][x1] = min(dist[y1][x1]+1,dist[min(y1+1,N-1)][x1])
        dist[min(y1+1,N-1)][x2] = min(dist[y1][x2]+1,dist[min(y1+1,N-1)][x2])
        dist[max(y2-1,0)][x1] = min(dist[y2][x1]+1,dist[max(y2-1,0)][x1])
        dist[max(y2-1,0)][x2] = min(dist[y2][x2]+1,dist[max(y2-1,0)][x2])
        dist[y1][min(x1+1,N-1)] = min(dist[y1][x1]+1,dist[y1][min(x1+1,N-1)])
        dist[y2][min(x1+1,N-1)] = min(dist[y2][x1]+1,dist[y2][min(x1+1,N-1)])
        dist[y1][max(x2-1,0)] = min(dist[y1][x2]+1,dist[y1][max(x2-1,0)])
        dist[y2][max(x2-1,0)] = min(dist[y2][x2]+1,dist[y2][max(x2-1,0)])

ans = [0]*(N-1)

for i in range(1,N):
    for j in range(i):
        ans[dist[i][j]-1] += 1

for i in ans:
    print(i)

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

dist = [[0 for i in range(N)] for j in range(N)]
for i in range(1,N):
    for j in range(i):
        dist[i][j]=i-j
dist[Y-1][X-1]=1

for i in range(N):
    y1 = min(Y-1+i,N-1)
    y2 = max(Y-1-i,0)
    for j in range(N):
        x1 = min(X-1+j,N-1)
        x2 = max(X-1-j,0)
        dist[min(y1+1,N-1)][x1] = min(dist[y1][x1]+1,dist[min(y1+1,N-1)][x1])
        dist[min(y1+1,N-1)][x2] = min(dist[y1][x2]+1,dist[min(y1+1,N-1)][x2])
        dist[max(y2-1,0)][x1] = min(dist[y2][x1]+1,dist[max(y2-1,0)][x1])
        dist[max(y2-1,0)][x2] = min(dist[y2][x2]+1,dist[max(y2-1,0)][x2])
        dist[y1][min(x1+1,N-1)] = min(dist[y1][x1]+1,dist[y1][min(x1+1,N-1)])
        dist[y2][min(x1+1,N-1)] = min(dist[y2][x1]+1,dist[y2][min(x1+1,N-1)])
        dist[y1][max(x2-1,0)] = min(dist[y1][x2]+1,dist[y1][max(x2-1,0)])
        dist[y2][max(x2-1,0)] = min(dist[y2][x2]+1,dist[y2][max(x2-1,0)])

ans = [0]*(N-1)

for i in range(1,N):
    for j in range(i):
        ans[dist[i][j]-1] += 1

for i in ans:
    print(i)
Buggy python submission (verdict: Runtime Error):
S = list(input())
ans = 0
if len(S)>=2:
    for i in range(0, len(S), 2):
        if S[i]!="h" or S[i+1]!="i":
            ans += 1
    if ans==0:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Fixed submission:
S = input()
list = ["hi","hihi","hihihi","hihihihi","hihihihihi"]
if S in list:
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
S = list(input())
ans = 0
for i in range(0, len(S), 2):
    if S[i]!="h" or S[i+1]!="i":
        ans += 1
if ans==0:
    print("Yes")
else:
    print("No")

Fixed submission:
S = input()
list = ["hi","hihi","hihihi","hihihihi","hihihihihi"]
if S in list:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
N, A, B = map(int, input().split())
ans = 0
while N >= 0:
    ans += min(A,N)
    N -= (A+B)
print(ans)

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

X = int(N / (A+B))
Y = int(N % (A+B))

ans += X*A+min(A,Y)

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


Fixed submission:
from collections import Counter

N, P = map(int, input().split())
S = list(map(int,list(input())))

def solve_2(S):
    ind = (i for i, x in enumerate(S, 1) if x % 2 == 0)
    return sum(ind)

def solve_5(S):
    ind = (i for i, x in enumerate(S, 1) if x % 5 == 0)
    return sum(ind)

def solve(S,P):
    if P == 2:
        return solve_2(S)
    if P == 5:
        return solve_5(S)
    S = S[::-1]
    T = [0] * len(S)
    T[0] = S[0] % P
    power = 1
    for i in range(1, len(S)):
        power *= 10
        power %= P
        T[i] = T[i-1] + power * S[i]
        T[i] %= P
    counter = Counter(T)
    return sum(x * (x - 1) // 2 for x in counter.values()) + counter[0]


print(solve(S,P))

Buggy python submission (verdict: Runtime Error):
dp = [[0 for i in range(N-j)] for j in range(N)]
dp
for j in range(N):
    dp[j][0]=(int(S[j])%mod)
    for i in range(1,N-j):
        dp[j][i]=((dp[j][i-1]*10+int(S[j+i]))%mod)
ans = 0
for i in range(N):
    ans += dp[i].count(0)
    
print(ans)

Fixed submission:
from collections import Counter

N, P = map(int, input().split())
S = list(map(int,list(input())))

def solve_2(S):
    ind = (i for i, x in enumerate(S, 1) if x % 2 == 0)
    return sum(ind)

def solve_5(S):
    ind = (i for i, x in enumerate(S, 1) if x % 5 == 0)
    return sum(ind)

def solve(S,P):
    if P == 2:
        return solve_2(S)
    if P == 5:
        return solve_5(S)
    S = S[::-1]
    T = [0] * len(S)
    T[0] = S[0] % P
    power = 1
    for i in range(1, len(S)):
        power *= 10
        power %= P
        T[i] = T[i-1] + power * S[i]
        T[i] %= P
    counter = Counter(T)
    return sum(x * (x - 1) // 2 for x in counter.values()) + counter[0]


print(solve(S,P))

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

Fixed submission:
from collections import Counter

N, P = map(int, input().split())
S = list(map(int,list(input())))

def solve_2(S):
    ind = (i for i, x in enumerate(S, 1) if x % 2 == 0)
    return sum(ind)

def solve_5(S):
    ind = (i for i, x in enumerate(S, 1) if x % 5 == 0)
    return sum(ind)

def solve(S,P):
    if P == 2:
        return solve_2(S)
    if P == 5:
        return solve_5(S)
    S = S[::-1]
    T = [0] * len(S)
    T[0] = S[0] % P
    power = 1
    for i in range(1, len(S)):
        power *= 10
        power %= P
        T[i] = T[i-1] + power * S[i]
        T[i] %= P
    counter = Counter(T)
    return sum(x * (x - 1) // 2 for x in counter.values()) + counter[0]


print(solve(S,P))
Buggy python submission (verdict: Runtime Error):
class UnionFind(object):
    def __init__(self, n=0):
        self.par = [i for i in range(n)]
        self.rank = [-1 for _ in range(n)]
        
    def find(self, x):
        if self.rank[x] < 0:
            return x
        else:
            self.rank[x] = self.find(self.rank[x])
            return self.rank[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if abs(x) < abs(y):
            x, y = y, x
        self.rank[x] += self.rank[y]
        self.rank[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)

n,m,k=map(int, input().split())
uf=UnionFind(n)
friend = [0]*n
for i in range(m):
    a,b=map(int, input().split())
    friend[a-1] +=1
    friend[b-1] +=1
    uf.union(a-1,b-1)

block = [[] for _ in range(n)]
for i in range(k):
    x,y=map(int, input().split())
    block[x-1].append(y-1)
    block[y-1].append(x-1)

ans = [0]*n
for i in range(n):
    ans[i] = uf.size(i)-1-friend[i]
    for j in block[i]:
        if uf.same(i,j):
            ans[i] -= 1
    ans[i] = str(ans[i])
    
print(" ".join(ans))

Fixed submission:
class UnionFind(object):
    def __init__(self, n=0):
        self.par = [i for i in range(n)]
        self.rank = [-1 for _ in range(n)] 

    def find(self, x):
        if self.rank[x] < 0:
            return x
        else:
            self.rank[x] = self.find(self.rank[x])
            return self.rank[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return 0

        if abs(x) < abs(y): 
            x, y = y, x 
        self.rank[x] += self.rank[y]
        self.rank[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)
    
    def size(self, x):
        return -self.rank[self.find(x)]

n,m,k=map(int, input().split())
uf=UnionFind(n)
friend = [0]*n
for i in range(m):
    a,b=map(int, input().split())
    friend[a-1] +=1
    friend[b-1] +=1
    uf.union(a-1,b-1)

block = [[] for _ in range(n)]
for i in range(k):
    x,y=map(int, input().split())
    block[x-1].append(y-1)
    block[y-1].append(x-1)

ans = [0]*n
for i in range(n):
    ans[i] = uf.size(i)-1-friend[i]
    for j in block[i]:
        if uf.same(i,j):
            ans[i] -= 1
    ans[i] = str(ans[i])
    
print(" ".join(ans))