Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
from itertools import accumulate

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

acc=list(accumulate(A))

d=[defaultdict(int) for i in range(N+1)]

for i in range(N):
    d[i+1][acc[i]%M]+=1
    for n,m in d[i].items():
        d[i+1][n]+=m

ans=0
for g in range(N):
    if acc[g]%M==0:
        ans+=d[g+1][acc[g]%M]
    else:
        ans+=d[g+1][acc[g]%M]-1
print(ans)

Fixed submission:
from collections import defaultdict
from itertools import accumulate

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

acc=list(accumulate(A))

d=defaultdict(int)

ans=0
for i in range(N):
    if acc[i]%M==0:
        d[acc[i]%M]+=1
        ans+=d[acc[i]%M]
    else:
        d[acc[i]%M]+=1
        ans+=d[acc[i]%M]-1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,M = (int(i) for i in input().split())  
A = [int(i) for i in input().split()]

a = 0
sum_A = {}

for g in range(N):
	a += A[g]
	amari = a%M
	if amari in sum_A.keys():
		sum_A[amari] += 1
	else:
		sum_A[amari] = 1

if sum_A.get(0)!=None:
	ans = sum_A[0]
else:
	ans = 0

for l in range(len(sum_A)):
	if sum_A[list(sum_A)[l]] >= 2:
		ans += (sum_A[list(sum_A)[l]]-1)*sum_A[list(sum_A)[l]]/2
print(int(ans))

Fixed submission:
from collections import defaultdict
from itertools import accumulate

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

acc=list(accumulate(A))

d=defaultdict(int)

ans=0
for i in range(N):
    if acc[i]%M==0:
        d[acc[i]%M]+=1
        ans+=d[acc[i]%M]
    else:
        d[acc[i]%M]+=1
        ans+=d[acc[i]%M]-1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,M = (int(i) for i in input().split())  
A = [int(i) for i in input().split()]

a = 0
sum_A = {}

for g in range(N):
	a += A[g]
	amari = a%M
	if amari in sum_A.keys():
		sum_A[amari] += 1
	else:
		sum_A[amari] = 1

if sum_A.get(0)!=None:
	ans = sum_A[0]
else:
	ans = 0
for l in range(len(sum_A)):
	if sum_A[list(sum_A)[l]] >= 2:
		ans += (sum_A[list(sum_A)[l]]-1)*sum_A[list(sum_A)[l]]/2
print(int(ans))

Fixed submission:
from collections import defaultdict
from itertools import accumulate

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

acc=list(accumulate(A))

d=defaultdict(int)

ans=0
for i in range(N):
    if acc[i]%M==0:
        d[acc[i]%M]+=1
        ans+=d[acc[i]%M]
    else:
        d[acc[i]%M]+=1
        ans+=d[acc[i]%M]-1
print(ans)

Buggy python submission (verdict: Runtime Error):
N,M = (int(i) for i in input().split())  
A = [int(i) for i in input().split()]

a = 0
sum_A = {}

for g in range(N):
	a += A[g]
	amari = a%M
	if amari in sum_A.keys():
		sum_A[amari] += 1
	else:
		sum_A[amari] = 1

ans = sum_A[0]
for l in range(len(sum_A)):
	if sum_A[list(sum_A)[l]] >= 2:
		ans += (sum_A[list(sum_A)[l]]-1)*sum_A[list(sum_A)[l]]/2
print(int(ans))

Fixed submission:
from collections import defaultdict
from itertools import accumulate

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

acc=list(accumulate(A))

d=defaultdict(int)

ans=0
for i in range(N):
    if acc[i]%M==0:
        d[acc[i]%M]+=1
        ans+=d[acc[i]%M]
    else:
        d[acc[i]%M]+=1
        ans+=d[acc[i]%M]-1
print(ans)

Buggy python submission (verdict: Runtime Error):
from scipy.special import comb

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

a = 0
sum_A = {}

for g in range(N):
	a += A[g]
	amari = a%M
	if amari in sum_A.keys():
		sum_A[amari] += 1
	else:
		sum_A[amari] = 1

ans = sum_A[0]
for l in range(len(sum_A)):
	if sum_A[list(sum_A)[l]] >= 2:
		ans += comb(sum_A[list(sum_A)[l]], 2, exact=True)
print(ans)

Fixed submission:
from collections import defaultdict
from itertools import accumulate

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

acc=list(accumulate(A))

d=defaultdict(int)

ans=0
for i in range(N):
    if acc[i]%M==0:
        d[acc[i]%M]+=1
        ans+=d[acc[i]%M]
    else:
        d[acc[i]%M]+=1
        ans+=d[acc[i]%M]-1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,M = (int(i) for i in input().split())  
A = [int(i) for i in input().split()]

a = A[0]
sum_A = []
for g in range(1,N+1):
	sum_A.append(a)
	if g<=N-1:
		a +=  A[g]

l=0
r=0
ans=0
while True:
	if r==l:
		if sum_A[l]%M==0:
			ans+=1
			r+=1
		else:
			r+=1
	else:
		if (sum_A[r]-sum_A[l])%M==0:
			ans+=1
			r+=1
		else:
			r+=1

	if r==N:
		l += 1
		r = l
	if l == N:
		break

print(ans)

Fixed submission:
from collections import defaultdict
from itertools import accumulate

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

acc=list(accumulate(A))

d=defaultdict(int)

ans=0
for i in range(N):
    if acc[i]%M==0:
        d[acc[i]%M]+=1
        ans+=d[acc[i]%M]
    else:
        d[acc[i]%M]+=1
        ans+=d[acc[i]%M]-1
print(ans)