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

def nCr(n,r):
    f = math.factorial
    return f(n) / f(r) / f(n-r)

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

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

# 1 <= N <= 10^5
# 2 <= M <= 10^9
# 1 <= A <= 10^9

S = []
total = 0
S.append(0)
for i in range(N):
    total = (total + A[i]) % M
    S.append(total)

oS = sorted(S)

count = 0

# print(oS)

cur_val = 0
number = 0
for i in range(0, N+1):
    if oS[i] == cur_val:
        number += 1
    if oS[i] > cur_val or i == N:
        if number >= 2:
            count += int(nCr(number, 2))
        # print(cur_val, number)
        number = 1
        cur_val = oS[i]

print(count)


Fixed submission:
import numpy as np
import math

def nCr(n,r):
    f = math.factorial
    return f(n) / f(r) / f(n-r)

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

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

# 1 <= N <= 10^5
# 2 <= M <= 10^9
# 1 <= A <= 10^9

S = []
total = 0
S.append(0)
for i in range(N):
    total = (total + A[i]) % M
    S.append(total)

oS = sorted(S)

count = 0

# print(oS)

cur_val = 0
number = 0
for i in range(0, N+1):
    if oS[i] == cur_val:
        number += 1
    if oS[i] > cur_val or i == N:
        if number >= 2:
            count += int(number * (number - 1) / 2)
        # print(cur_val, number)
        number = 1
        cur_val = oS[i]

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import math

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

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

# 1 <= N <= 10^5
# 2 <= M <= 10^9
# 1 <= A <= 10^9

dp = np.zeros(N+1, dtype=int)

dp[N] = 0

total = 0
mods = dict()
mods[0] = 1

for i in reversed(range(N)):
    newdic = dict()
    for mod, count in mods.items():
        newm = (A[i] + mod) % M
        if newm == 0:
            total += count
        newdic[newm] = count

    if 0 in newdic.keys():
        newdic[0] += 1
    else:
        newdic[0] = 1
    mods = newdic
        # print(mods)
    
print(total)


Fixed submission:
import numpy as np
import math

def nCr(n,r):
    f = math.factorial
    return f(n) / f(r) / f(n-r)

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

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

# 1 <= N <= 10^5
# 2 <= M <= 10^9
# 1 <= A <= 10^9

S = []
total = 0
S.append(0)
for i in range(N):
    total = (total + A[i]) % M
    S.append(total)

oS = sorted(S)

count = 0

# print(oS)

cur_val = 0
number = 0
for i in range(0, N+1):
    if oS[i] == cur_val:
        number += 1
    if oS[i] > cur_val or i == N:
        if number >= 2:
            count += int(number * (number - 1) / 2)
        # print(cur_val, number)
        number = 1
        cur_val = oS[i]

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import math

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

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

# 1 <= N <= 10^5
# 2 <= M <= 10^9
# 1 <= A <= 10^9

dp = np.zeros(N+1, dtype=int)

dp[N] = 0

total = 0
mods = list()
mods.append(0)

for i in reversed(range(N)):
    for j in range(len(mods)):
        newm = (A[i] + mods[j]) % M
        if newm == 0:
            total += 1
        mods[j] = newm
    mods.append(0)
    # print(mods)
    
print(total)


Fixed submission:
import numpy as np
import math

def nCr(n,r):
    f = math.factorial
    return f(n) / f(r) / f(n-r)

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

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

# 1 <= N <= 10^5
# 2 <= M <= 10^9
# 1 <= A <= 10^9

S = []
total = 0
S.append(0)
for i in range(N):
    total = (total + A[i]) % M
    S.append(total)

oS = sorted(S)

count = 0

# print(oS)

cur_val = 0
number = 0
for i in range(0, N+1):
    if oS[i] == cur_val:
        number += 1
    if oS[i] > cur_val or i == N:
        if number >= 2:
            count += int(number * (number - 1) / 2)
        # print(cur_val, number)
        number = 1
        cur_val = oS[i]

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import math

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

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

# 1 <= N <= 10^5
# 2 <= M <= 10^9
# 1 <= A <= 10^9

dp = np.zeros(N+1, dtype=int)

dp[N] = 0

for i in reversed(range(N)):
    # N-1 -> 0
    total = 0
    for j in range(i, N):
        total = (total + A[j]) % M
        if total == 0:
            dp[i] = 1 + dp[j+1]
            break

# print(dp)
print(sum(dp))


Fixed submission:
import numpy as np
import math

def nCr(n,r):
    f = math.factorial
    return f(n) / f(r) / f(n-r)

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

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

# 1 <= N <= 10^5
# 2 <= M <= 10^9
# 1 <= A <= 10^9

S = []
total = 0
S.append(0)
for i in range(N):
    total = (total + A[i]) % M
    S.append(total)

oS = sorted(S)

count = 0

# print(oS)

cur_val = 0
number = 0
for i in range(0, N+1):
    if oS[i] == cur_val:
        number += 1
    if oS[i] > cur_val or i == N:
        if number >= 2:
            count += int(number * (number - 1) / 2)
        # print(cur_val, number)
        number = 1
        cur_val = oS[i]

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import math

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

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

# 1 <= N <= 10^5
# 2 <= M <= 10^9
# 1 <= A <= 10^9

dp = np.zeros(N+1, dtype=int)

dp[N] = 0

for i in reversed(range(N)):
    # N-1 -> 0
    total = 0
    for j in range(i, N):
        total += A[j]
        if total % M == 0:
            dp[i] = 1 + dp[j+1]
            break

# print(dp)
print(sum(dp))


Fixed submission:
import numpy as np
import math

def nCr(n,r):
    f = math.factorial
    return f(n) / f(r) / f(n-r)

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

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

# 1 <= N <= 10^5
# 2 <= M <= 10^9
# 1 <= A <= 10^9

S = []
total = 0
S.append(0)
for i in range(N):
    total = (total + A[i]) % M
    S.append(total)

oS = sorted(S)

count = 0

# print(oS)

cur_val = 0
number = 0
for i in range(0, N+1):
    if oS[i] == cur_val:
        number += 1
    if oS[i] > cur_val or i == N:
        if number >= 2:
            count += int(number * (number - 1) / 2)
        # print(cur_val, number)
        number = 1
        cur_val = oS[i]

print(count)