qyliang/CodeNanoFix huggingface dataset:
Buggy code:
import sys
input = sys.stdin.readline
from collections import defaultdict
from itertools import accumulate


def read():
    N, M = map(int, input().strip().split())
    A = list(map(int, input().strip().split()))
    return N, M, A

def solve(N, M, A):
    D = defaultdict(int)
    S = [0 for i in range(N+1)]
    for i in range(N):
        s = (S[i] + A[i]) % M
        S[i+1] = s
        D[s] += 1
    ans = 0
    k = 0
    for i in range(N-1):
        ans += D[k]
        D[k] -= 1
        k += A[i]
        k %= M
    return ans


if __name__ == '__main__':
    inputs = read()
    print(solve(*inputs))


Fixed code:
import sys
input = sys.stdin.readline
from collections import defaultdict
from itertools import accumulate


def read():
    N, M = map(int, input().strip().split())
    A = list(map(int, input().strip().split()))
    return N, M, A

def solve(N, M, A):
    D = defaultdict(int)
    S = [0 for i in range(N+1)]
    for i in range(N):
        s = (S[i] + A[i]) % M
        S[i+1] = s
        D[s] += 1
    ans = 0
    k = 0
    for i in range(N):
        ans += D[k]
        k += A[i]
        k %= M
        D[k] -= 1
    return ans


if __name__ == '__main__':
    inputs = read()
    print(solve(*inputs))
Buggy code:
n,m=map(int,input().split())
a=list(map(int,input().split()))

cnt=0
dic={}
aaa=0
zero=0
for aa in a:
    aaa+=aa
    amod=aa%m
    if amod==0:
        cnt+=1
        zero+=1
    
    if (m-amod)%m in dic:
        cnt+=dic[(m-amod)%m]
    
    if aaa%m in dic:
        dic[aaa%m]+=1+zero
    else:
        dic[aaa%m]=1+zero
    #print(aaa,aa,aaa%m,dic)
print(cnt)



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

cnt=0
dic={}
dic[0]=1
aaa=0
for aa in a:
    aaa+=aa

    if aaa%m in dic:
        cnt+=dic[aaa%m]
        dic[aaa%m]+=1
    else:
        dic[aaa%m]=1
            #print(aaa,aa,aaa%m,dic)
    #print(dic)
print(cnt)
Buggy code:
from itertools import accumulate
from collections import Counter
n,m=map(int,input().split())
s=[0]+list(map(lambda x:x%m,list(accumulate(list(map(int,input().split()))))))
ans=0
for i in Counter(s):
    ans+=(d[i]*(d[i]-1)//2)
print(ans)

Fixed code:
from itertools import accumulate
from collections import Counter
n,m=map(int,input().split())
s=[0]+list(map(lambda x:x%m,list(accumulate(list(map(int,input().split()))))))
ans=0
for i in Counter(s).values():
    ans+=(i*(i-1)//2)
print(ans)
Buggy code:
N,M=map(int,input().split())
A=[0]+list(map(int,input().split()))

a=0
m=[0]*N
for i in range(N):
    a+=A[i]%M
    a%=M
    m[i]=a

m.sort()
ans=0
cnt=0
for i in range(N):
    if m[i]==m[i+1]:
        cnt+=1
    else:
        ans+=cnt*(cnt-1)//2
        cnt=1
ans+=cnt*(cnt-1)//2
print(ans)

Fixed code:
N,M=map(int,input().split())
A=[0]+list(map(int,input().split()))

a=0
m=[0]*(N+1)
for i in range(N+1):
    a+=A[i]%M
    a%=M
    m[i]=a

m.sort()
ans=0
cnt=1
for i in range(N):
    if m[i+1]==m[i]:
        cnt+=1
    else:
        ans+=cnt*(cnt-1)//2
        cnt=1
ans+=cnt*(cnt-1)//2
print(ans)
Buggy code:
N,M = map(int,input().split)
A = list(map(int,input().split))

R = [A[0]%M]

for i in range(1,N):
  R.append((R[-1]+A[i])%M)
  
  
k = set(R)
dic = {i:0 for i in k}
for item in R:
  dic[item]+=1


#print(dic)
ans = dic[0]*(dic[0]+1)/2
for i in k:
  if i !=0 :
    ans += dic[i]*(dic[i]-1)/2

  
print(int(ans))

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

R = [A[0]%M]


for i in range(1,N):
  R.append((R[-1]+A[i])%M)

k = set(R)
dic = {i:0 for i in k}
for item in R:
  dic[item]+=1
  
  
ans = 0
if 0 in dic:
  ans = (dic[0]*(dic[0]+1))/2


for i in k:
  if i !=0 :
    ans += (dic[i]*(dic[i]-1))/2
    

    
print(int(ans))
Buggy code:
def main():
    import sys
    input = sys.stdin.readline
    from collections import Counter
    from itertools import accumulate

    n,m = map(int, input().split())
    a = [0] + list(map(lambda x: x % M, accumulate(map(int, input().split()))))
    c = Counter(a)
    res = 0
    for k, v in c.items():
            res += v*(v-1)//2
    print(res)
    
if __name__ == '__main__':
    main()

Fixed code:
def main():
    import sys
    input = sys.stdin.readline
    from collections import Counter
    from itertools import accumulate

    n,m = map(int, input().split())
    a = [0] + list(map(lambda x: x % m, accumulate(map(int, input().split()))))
    c = Counter(a)
    res = 0
    for k, v in c.items():
            res += v*(v-1)//2
    print(res)
    
if __name__ == '__main__':
    main()
Buggy code:
N,M = map(int,input().split())
Alist = list(map(int, input().strip().split()))
r = [0]*N
r[0] = Alist[0]
for i in range(1,len(Alist)):
    r[i] = r[i-1] + Alist[i]
for i in range(len(r)):
    r[i] = r[i]%M
r.sort()
p = []
m = 0
for i in range(1,len(r)):
    m = m+1
    if r[i-1] != r[i]:
        p.append(m)
        m = 0
def combi(n):
    if n == 0:
        return 0
    if n == 1:
        return 0
    else:
        return (n*(n-1))/2
s = 0
for i in range(len(p)):
    s = s + combi(p[i])
s = s + p[0]
print(int(s))

Fixed code:
N,M = map(int,input().split())
Alist = list(map(int, input().strip().split()))
r = [0]*N
r[0] = Alist[0]
for i in range(1,len(Alist)):
    r[i] = r[i-1] + Alist[i]
for i in range(len(r)):
    r[i] = r[i]%M
r.sort()
p = []
m = 0
for i in range(len(r)-1):
    m = m+1
    if r[i] != r[i+1]:
        p.append(m)
        m = 0
    if i == len(r)-2:
        p.append(m+1)
x = 0
for i  in range(len(r)):
    if r[i] == 0:
        x = x +1
def combi(n):
    if n == 0:
        return 0
    if n == 1:
        return 0
    else:
        return (n*(n-1))/2
s = 0
for i in range(len(p)):
    s = s + combi(p[i])
s = s + x
print(int(s))
Buggy code:
from collections import Counter
from itertools import accumulate
N, M, *A = map(int, open('0').read().split())
B = [b%M for b in accumulate(A)]
C = Counter(B)
ans = C[0]
ans += sum(C[k]*(C[k]-1)//2 for k in C.keys())
print(ans)

Fixed code:
from collections import Counter
from itertools import accumulate
N, M, *A = map(int, open(0).read().split())
B = [b%M for b in accumulate(A)]
C = Counter(B)
ans = C[0]
for k in C.keys():
  ans += C[k]*(C[k]-1)//2
print(ans)
Buggy code:
n, m = map(int, input().split())
l = list(map(int, input().split()))

l = [0] + l
from itertools import accumulate
cum =list(accumulate(l))
print(cum)
cum = [c%m for c in cum]

d = {}
ans = 0
for i in range(n+1):
  if cum[i] not in d:
    d[cum[i]] = 1
  else:
    ans += d[cum[i]]
    d[cum[i]] += 1
print(ans)

Fixed code:
n, m = map(int, input().split())
l = list(map(int, input().split()))

l = [0] + l
from itertools import accumulate
cum =list(accumulate(l))
cum = [c%m for c in cum]

d = {}
ans = 0
for i in range(n+1):
  if cum[i] not in d:
    d[cum[i]] = 1
  else:
    ans += d[cum[i]]
    d[cum[i]] += 1
print(ans)
Buggy code:
from collections import defaultdict
#from collections import deque

N, K=map(int, input().split())
A=list(map(int, input().split()))
for i in range(N):
    A[i]-=1
s=[0 for _ in range(N+1)]
for i in range(N):
    s[i+1]=(s[i]+A[i])%K
d=defaultdict(int)
ans=0
#q=deque()
for j in range(N+1):
    ans+=d[s[j]]
    d[s[j]]+=1
    #q.append(s[j])
    #if len(q)==K:
        #d[q[0]]-=1
        #q.popleft()
print(ans)

Fixed code:
from collections import defaultdict
#from collections import deque

N, K=map(int, input().split())
A=list(map(int, input().split()))
#for i in range(N):
    #A[i]-=1
s=[0 for _ in range(N+1)]
for i in range(N):
    s[i+1]=(s[i]+A[i])%K
d=defaultdict(int)
ans=0
#q=deque()
for j in range(N+1):
    ans+=d[s[j]]
    d[s[j]]+=1
    #q.append(s[j])
    #if len(q)==K:
        #d[q[0]]-=1
        #q.popleft()
print(ans)
Buggy code:
n, m = map(int, input().split())
a = list(map(int, input().split()))
memo = [0]
d = {0: 1}
for ai in a:
  memo.append((memo[-1] + ai) % m)
  mi = memo[-1]
  if mi in d:
    d[mi] += 1
  else:
    d[mi] = 1
ans = 0
for k in d:
  c = d[k]
  ans += c * (c-1)
print(ans)
  


Fixed code:
n, m = map(int, input().split())
a = list(map(int, input().split()))
memo = [0]
d = {0: 1}
for ai in a:
  memo.append((memo[-1] + ai) % m)
  mi = memo[-1]
  if mi in d:
    d[mi] += 1
  else:
    d[mi] = 1
ans = 0
for k in d:
  c = d[k]
  ans += c * (c-1) // 2
print(ans)
Buggy code:
n,m=map(int,input().split())
a=list(map(int,input().split()))
from collections import Counter
c=[0]
for i in a:
    c.append((c[-1]+a)%m)
cc=Counter(c)
ans=0
for i in cc.values():
    ans+=i*(i-1)//2
print(ans)


Fixed code:
n,m=map(int,input().split())
a=list(map(int,input().split()))
from collections import Counter
c=[0]
for i in a:
    c.append((c[-1]+i)%m)
cc=Counter(c)
ans=0
for i in cc.values():
    ans+=i*(i-1)//2
print(ans)
Buggy code:
from collections import Counter
from itertools import accumulate

N, M = map(int, input().split())
A = map(int, input().split())
acc = [0] 
acc.extend(accumulate(A))
acc = Counter(a % M for a in acc)
ans = sum(c * (c - 1) // 2 for c in acc.values())

Fixed code:
from collections import Counter
from itertools import accumulate
 
N, M = map(int, input().split())
acc = [0]
acc.extend(accumulate(map(int, input().split())))

acc = Counter(a%M for a in acc)
print(sum(c*(c-1)//2 for c in acc.values()))
Buggy code:
from collections import Counter

n, m = map(int, input().split())
a = list(map(int, input().split()))
SUM = [0]

for i in a:
    SUM.append((SUM[-1]+i)%m)

SUM.pop(0)
c = Counter(SUM)
C = c.most_common()
ans = 0

for i in C:
    if i[1] > 1:
        ans += i[1]*(i[1]+1)//2
    else:
        break
print(ans)

Fixed code:
from collections import Counter

n, m = map(int, input().split())
a = list(map(int, input().split()))
SUM = [0]

for i in a:
    SUM.append((SUM[-1]+i)%m)

#SUM.pop(0)
c = Counter(SUM)
C = c.most_common()
C_srt = sorted(C)
ans = 0

for i in C:
    if i[1] > 1:
        '''
        if i[0] == 0:
            ans += i[1]*(i[1]+1)//2
        else:
        '''
        ans += i[1]*(i[1]-1)//2
    else:
        break
print(ans)
Buggy code:
import collections
n, m = map(int, input().split())
A = [int(i) for i in input().split()]

R = [0]*n
a = 0
for i in range(n):
    a += A[i]
    a %= m
    R[i] = a


def nc2(n):
    return n*(n-1)//2


c = collections.Counter(R)
ans = 0
for r in set(R):
    ans += nc2(c[r])
print(ans)


Fixed code:
n,m=map(int,input().split())
A=[int(i) for i in input().split()]
R=[0]
a=0
for i in range(n):
  a+=A[i]
  a%=m
  R.append(a)
def nc2(n):
  return n*(n-1)//2
import collections
c=collections.Counter(R)
ans=0
for r in set(R):
  ans+=nc2(c[r])
print(ans)
Buggy code:
n,m=map(int, input().split())
h=list(map(int, input().split()))
a=[0]*(n+1)
num={0:1}
for i in range(n):
    a[i+1]=(a[i]+h[i])%m
    if a[i+1] in num:
        num[a[i+1]]+=1
    else:
        num[a[i+1]]=1

ans=0
for i in num.values():
    if i>2:
        ans+=(i*(i-1))//2
print(ans)

Fixed code:
n,m=map(int, input().split())
h=list(map(int, input().split()))
a=[0]*(n+1)
num={0:1}
for i in range(n):
    a[i+1]=(a[i]+h[i])%m
    if a[i+1] in num:
        num[a[i+1]]+=1
    else:
        num[a[i+1]]=1

ans=0
for i in num.values():
    if i>1:
        ans+=(i*(i-1))//2
print(ans)
Buggy code:
# coding: utf-8
from collections import defaultdict

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

B=[]

s=0
for a in A:
    s+=a
    B.append(s)
F=defaultdict(int)
for b in B:
    F[b%M]+=1
ans=0
for b in B:
    if b%M==0:ans+=1
    ans+=int((F[b%M]-1)/2)
print(ans)

Fixed code:
# coding: utf-8
from collections import defaultdict

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

B=[0]

s=0
for a in A:
    s+=a
    B.append(s)
F=defaultdict(int)
for b in B:
    F[b%M]+=1
ans=0
for n in F.values():
    ans+=n*(n-1)//2
print(ans)
Buggy code:
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, A: "List[int]"):
    c = [0] * M
    c[0] = 1
    total = 0
    for a in A:
        total = (total + a) % M
        c[total] += 1
    res = 0
    for t in c:
        res += t * (t-1) // 2
    print(res)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, M, A)

if __name__ == '__main__':
    main()


Fixed code:
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, A: "List[int]"):
    c = dict()
    c[0] = 1
    total = 0
    res = 0
    for a in A:
        total = (total + a) % M
        if total in c:
            c[total] += 1
        else:
            c[total] = 1
        res += c[total] - 1
    print(res)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, M, A)

if __name__ == '__main__':
    main()
Buggy code:
from collections import defaultdict

N, M = map(int, input().split())
A = list(map(int, input().split()))
cumS = [0]
for a in A:
    cumS.append(a + cumS[-1])
cumS_rem = defaultdict(int)
for c in cumS:
    r = c % M
    cumS_rem[r] += 1
ans = 0
for r, n_r in cumS_rem.items()
    if n_r > 1:
        ans += n_r*(n_r-1)//2
print(ans)

Fixed code:
from collections import defaultdict

N, M = map(int, input().split())
A = list(map(int, input().split()))
cumS = [0]
for a in A:
    cumS.append(a + cumS[-1])
cumS_rem = defaultdict(int)
for c in cumS:
    r = c % M
    cumS_rem[r] += 1
ans = 0
for r, n_r in cumS_rem.items():
    if n_r > 1:
        ans += n_r*(n_r-1)//2
print(ans)
Buggy code:
n,m=map(int,input().split())
l=[int(i) for i in input().split()]
for i in l:
    w.append((i+w[-1])%m)
ans=0
d={}
for i in w:
    if i in d:
        d[i]+=1
    else:
        d[i]=1
for i in d:
    ans+=d[i]*(d[i]-1)
print(ans//2)

Fixed code:
n,m=map(int,input().split())
l=[int(i) for i in input().split()]
w=[0]
for i in l:
    w.append((i+w[-1])%m)
ans=0
d={}
for i in w:
    if i in d:
        d[i]+=1
    else:
        d[i]=1
for i in d:
    ans+=d[i]*(d[i]-1)
print(ans//2)
Buggy code:
from collections import defaultdict
N, M = map(int, input().split())
A = list(map(int, input().split()))

ans = 0
hash = defaultdict(int())
i = 0
for a in A:
    i = (i+a) % M
    hash[i] += 1
for h in list(hash.keys()):
    ans += hash[h] * (hash[h]-1) // 2

print(ans)

Fixed code:
from collections import defaultdict
N, M = map(int, input().split())
A = list(map(int, input().split()))

ans = 0
hash = defaultdict(int)
hash[0] = 1
i = 0
for a in A:
    i = (i+a) % M
    hash[i] += 1
for h in list(hash.keys()):
    ans += hash[h] * (hash[h]-1) // 2

print(ans)
Buggy code:
N,M = map(int, input().split())
L = list(map(int, input().split()))
import itertools as it
L=[0]+list(map(lambda x : x % M,it.accumulate(L)))
S=sorted(L)
#print(S)
tmp = -1
ans = 0
cnt=0
def nC2(n):
    return int(n*(n-1)/2)
for x in S:
    
    if tmp == x:
        cnt += 1
    else:
        ans += nC2(cnt+1)
        cnt = 0
    tmp = x
print(ans)

Fixed code:
N,M = map(int, input().split())
L = list(map(int, input().split()))
import itertools as it
L=[0]+list(map(lambda x : x % M,it.accumulate(L)))
S=sorted(L)
#print(S)
tmp = -1
ans = 0
cnt=0
def nC2(n):
    return int(n*(n-1)/2)
for i in range(len(S)):
    
    if tmp == S[i]:
        cnt += 1
        if len(S)-1 == i:
            ans += nC2(cnt+1)
    else:
        ans += nC2(cnt+1)
        cnt = 0
    tmp = S[i]

print(ans)
Buggy code:
from collections import Counter
N, M = (list)(map(int, input().split()))
A = (list)(map(int, input().split()))
A[0] %= M

for i in range(1, N):
    A[i] += A[i-1]
    A[i] %= M

ans = 0

C = Counter(A)
for num, val in C:
    if num == 0:
        ans += val
    if val >= 2:
        ans += val*(val-1)//2
print(ans)


Fixed code:
from collections import Counter
N, M = (list)(map(int, input().split()))
A = (list)(map(int, input().split()))
A[0] %= M

for i in range(1, N):
    A[i] += A[i-1]
    A[i] %= M

ans = 0

C = Counter(A)
for num, val in C.items():
    if num == 0:
        ans += val
    if val >= 2:
        ans += val*(val-1)//2
print(ans)
Buggy code:
import numpy as np
(n, m) = list(map(int, input().split()))
a = np.array(list(map(int, input().split()))).astype("int64") 
a = np.cumsum(a)
a %= m
count = np.sum(a == 0)
a.sort()

tc = 1
for i in range(1, n):
    if a[i - 1] == a[i]:
        tc += 1
    else:
        count += tc * (tc - 1) // 2
        tc = 1
print(count)

Fixed code:
import numpy as np
(n, m) = list(map(int, input().split()))
a = np.array(list(map(int, input().split()))).astype("int64") 
a = np.cumsum(a)
a %= m
count = np.sum(a == 0)
a.sort()
tc = 1
for i in range(1, n):
    if a[i - 1] == a[i]:
        tc += 1
    else:
        count += tc * (tc - 1) // 2
        tc = 1
else:
    count += tc * (tc - 1) // 2
print(count)
Buggy code:
N, M = [int(x) for x in input().split()]

sum_c = 0
dic = {0:1}
for x in input().split():
    x = int(x)
    sum_c += x
    a = sum_c//M
    
    if dic.get(a,0) == 0:
        dic[a] = 1
    else:
        dic[a] += 1

ans = 0
ans += dic[0]*(dic[0]-1)

for v in dic.values():
    ans += v*(v-1)

print(ans)

Fixed code:
N, M = [int(x) for x in input().split()]

sum_c = 0
dic = {0:1}
for x in input().split():
    x = int(x)
    sum_c += x
    a = sum_c%M
    
    if dic.get(a,0) == 0:
        dic[a] = 1
    else:
        dic[a] += 1

ans = 0
ans += dic[0]*(dic[0]-1)/2
dic.pop(0)
for v in dic.values():
    ans += v*(v-1)/2
print(int(ans))
Buggy code:
import collections
import numpy as np

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

A = np.array(A,dtype='int64')
C = np.append([0],np.cumsum(A))
L = [i%M for i in C]
L_c = collections.Counter(L)

ans = 0
for i in L_c.values():
	S = i * (i-1) / 2
    ans+=S
print(int(ans))

Fixed code:
import collections
import numpy as np

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

A = np.array(A,dtype='int64')
C = np.append([0],np.cumsum(A))
L = [i%M for i in C]
L_c = collections.Counter(L)

ans = 0
for i in L_c.values():
    S = i * (i-1) / 2
    ans+=S
    
print(int(ans))
Buggy code:
n,m=map(int,input().split())
a=list(map(int,input().split()))
count=0
sum=0
alist=[]
for i in a:
    sum+=i
    alist.append(sum%m)
alist.sort()
k=0
n=0
for j in alist:
    n+=1
    if k!=j:
        count+=(n*(n-1)/2)
        n=0
    k=j
print(int(count))

Fixed code:
n,m=map(int,input().split())
a=list(map(int,input().split()))
count=0
sum=0
alist=[0]
for i in a:
    sum+=i
    alist.append(sum%m)
alist.sort()
k=-1
n=0
for j in alist:
    if k!=j:
        count+=(n*(n-1)/2)
        n=0
    n+=1
    k=j
count+=(n*(n-1)/2)
print(int(count))
Buggy code:
# coding: utf-8
import collections
import math
list = input().split()
N = int(list[0])
M = int(list[1])
a = input().split()
x = 0
hako = [0]
for i in a:
    hako.append(int(i))
B = []
b = 0
for i in hako:
    b += i
    B.append(b%M)
c = collections.Counter(B)
aaa =[]
for i in c:
    if c[i] >= 2:
        aaa.append(c[i])
def kumi(n):
    return int(math.factrial(n)//(2*math.factrial(n-2)))
for i in aaa:
    x += kumi(i)
print(x)

Fixed code:
# coding: utf-8
import collections
import math
list = input().split()
N = int(list[0])
M = int(list[1])
a = input().split()
x = 0
hako = [0]
for i in a:
    hako.append(int(i))
B = []
b = 0
for i in hako:
    b += i
    B.append(b%M)
c = collections.Counter(B)
aaa =[]
for i in c:
    if c[i] >= 2:
        aaa.append(c[i])
def kumi(n):
    return int(math.factorial(n)/(2*math.factorial(n-2)))
for i in aaa:
    x += kumi(i)
print(x)
Buggy code:
n, m = map(int, input().split())
d = {0: 1}
asum = 0
ans = 0
for a in map(int, input().split()):
    asum = (asum + a) % m
    if asum in d:
        ans += d[asum]
        d[asum] += 1
    else:
        d[asum] = 1
print(ans

Fixed code:
n, m = map(int, input().split())
d = {0: 1}
asum = 0
ans = 0
for a in map(int, input().split()):
    asum = (asum + a) % m
    if asum in d:
        ans += d[asum]
        d[asum] += 1
    else:
        d[asum] = 1
print(ans)
Buggy code:
n,m=map(int,input().split())
a=list(map(int,input().split()))
a[0]%=m
for i in range(1,n):
	a[i]+=a[i-1]
	a[i]%=m
a.sort()
p=0
s=0
for i in range(1,n):
	if a[i]-a[p]:
		p=i-p
		s+=p*(p-1)/2
		p=i
p=n-p
s+=p*(p+1)/2
print(s)

Fixed code:
n,m=map(int,input().split())
a=[0]+list(map(int,input().split()))
a[0]%=m
for i in range(1,n+1):
	a[i]+=a[i-1]
	a[i]%=m
a.sort()
p=0
s=0
for i in range(1,n+1):
	if a[i]-a[p]:
		l=a[i]
		p=i-p
		s+=p*(p-1)
		p=i
p=n-p
s+=p*(p+1)
print(int(s/2))
Buggy code:
from collections import Counter
from itertools import accumulate
from functools import reduce

N, M = map(int, input().split())
A = [int(x) for x in input().split()]

c = Counter([0] + [x % M for x in accumulate(A)])
ans = reduce(add, [v*(v-1)//2 for v in c.values()])
print(ans)


Fixed code:
from collections import Counter
from itertools import accumulate
from functools import reduce

N, M = map(int, input().split())
A = [int(x) for x in input().split()]

c = Counter([0] + [x % M for x in accumulate(A)])
ans = reduce(lambda x,y:x+y, [v*(v-1)//2 for v in c.values()])
print(ans)
Buggy code:
n, m = map(int, input().split(' '))
a = map(int, input().split(' '))

d = {0: 1}
asum = 0
for aa in a:
    asum = (asum + aa) % m
    if asum in d:
        d[asum] += 1
    else:
        d[asum] = 1


ans = 0
for v in d.values():
    ans += v * (v - 1) / 2

print(ans)

Fixed code:
n, m = map(int, input().split(' '))
a = map(int, input().split(' '))

d = {0: 1}
asum = 0
for aa in a:
    asum = (asum + aa) % m
    if asum in d:
        d[asum] += 1
    else:
        d[asum] = 1


ans = 0
for v in d.values():
    ans += int(v * (v - 1) / 2)

print(ans)
Buggy code:
N,M=map(int,input().split())
A=[int(i) for i in input().split()]
S=[0 for i in range(N+1)]
for i in range(N):
    S[i+1]=(S[i]+A[i])%M
D=dict()
for i in range(N+1):
    if S[i] in D:
        D[S[i]]+=1
    else:
        D[S[i]]=1
print(D)
for si in D:
    print(D[si])
print(S)

Fixed code:
N,M=map(int,input().split())
A=[int(i) for i in input().split()]
S=[0 for i in range(N+1)]
for i in range(N):
  S[i+1]=(S[i]+A[i])%M
D=dict()
ans=0
for i in range(N+1):
  if S[i] in D:
    D[S[i]]+=1
  else:
    D[S[i]]=1
  ans+=D[S[i]]-1
print(ans)
Buggy code:
from collections import Counter
N,M = map(int,input().split())
A = list(map(int,input().split()))

S = [0]*(N+1)
for i in range(N):
    S[i+1] = (S[i]+A[i]) % M

C = Counter(S)

Ans = 0
for v in C.values():
    if v == 1:
        break
    else:
        Ans += v*(v-1)//2

print(Ans)

Fixed code:
from collections import Counter
N,M = map(int,input().split())
A = list(map(int,input().split()))

S = [0]*(N+1)
for i in range(N):
    S[i+1] = (S[i]+A[i]) % M

C = Counter(S)

Ans = 0
for v in C.values():
    if v != 1:
        Ans += v*(v-1)//2

print(Ans)
Buggy code:
import math
#n,m = 3,2
#a = [4,1,5]
n, m = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [0 for i in range(n)]
for i,ai in enumerate(a):
    if i == 0:
        b[i] = ai % m
    else:
        b[i] = (ai + b[i-1]) % m

ans = 0

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

for i in range(m):
    c = b.count(i)    
    if c >= 2:
        ans += combinations_count(c,2)
ans += b.count(0)

print(ans)


Fixed code:
import math
import collections

#n,m = 3,2
#a = [4,1,5]
n, m = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [0 for i in range(n)]
for i,ai in enumerate(a):
    if i == 0:
        b[i] = ai % m
    else:
        b[i] = (ai + b[i-1]) % m

ans = 0

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

c = collections.Counter(b)
for i in c.values():
    if i >= 2:
        ans += combinations_count(i,2)

#for i in range(m):
#    c = b.count(i)    
#    if c >= 2:
#        ans += combinations_count(c,2)
ans += b.count(0)

print(ans)