Buggy python submission (verdict: Runtime Error):
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():
    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)

Fixed submission:
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)

Buggy python submission (verdict: Runtime Error):
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%m,2)
ans += b.count(0)

print(ans)


Fixed submission:
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)

Buggy python submission (verdict: Time Limit Exceeded):
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 submission:
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)