Buggy python submission (verdict: Time Limit Exceeded):
import sys
import collections
from collections import Counter
# from collections import deque
# from collections import defaultdict
import itertools
# from itertools import accumulate
# from itertools import permutations
# from itertools import combinations
# from itertools import takewhile
from itertools import compress
# import functools
# from functools import reduce
import math
# from math import gcd
# from math import inf
# from math import ceil
# from math import floor
# from math import log10
# from math import log2
# from math import log
from math import factorial

# import re

input = sys.stdin.readline

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

B = list(itertools.accumulate(A))

ans = 0
for l in range(N):
    for r in range(l, N):
        t = B[r] - (B[l - 1] if l - 1 >=0 else 0)
        if t % M == 0:
            ans += 1

print(ans)


Fixed submission:
import sys
import collections
from collections import Counter
# from collections import deque
# from collections import defaultdict
import itertools
# from itertools import accumulate
# from itertools import permutations
# from itertools import combinations
# from itertools import takewhile
from itertools import compress
import functools
# from functools import reduce
import math
# from math import gcd
# from math import inf
# from math import ceil
# from math import floor
# from math import log10
# from math import log2
# from math import log
from math import factorial

# import re

input = sys.stdin.readline

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

B = list(itertools.accumulate(A))
C = [0] + [x % M for x in B]

ans = 0

CNT = collections.Counter(C)

for k, v in CNT.items():
    if v >= 2:
        ans += v * (v - 1) // 2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import collections
from collections import Counter
# from collections import deque
# from collections import defaultdict
import itertools
# from itertools import accumulate
# from itertools import permutations
# from itertools import combinations
# from itertools import takewhile
from itertools import compress
# import functools
# from functools import reduce
import math
# from math import gcd
# from math import inf
# from math import ceil
# from math import floor
# from math import log10
# from math import log2
# from math import log
from math import factorial

# import re

input = sys.stdin.readline

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

B = list(itertools.accumulate(A))

ans = 0
for l in range(N):
    for r in range(l, N):
        t = B[r] - (B[l - 1] if l - 1 >=0 else 0)
        if t % M == 0:
            ans += 1

print(ans)


Fixed submission:
import sys
import collections
from collections import Counter
# from collections import deque
# from collections import defaultdict
import itertools
# from itertools import accumulate
# from itertools import permutations
# from itertools import combinations
# from itertools import takewhile
from itertools import compress
import functools
# from functools import reduce
import math
# from math import gcd
# from math import inf
# from math import ceil
# from math import floor
# from math import log10
# from math import log2
# from math import log
from math import factorial

# import re

input = sys.stdin.readline

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

B = list(itertools.accumulate(A))
C = [0] + [x % M for x in B]

ans = 0

CNT = collections.Counter(C)

for k, v in CNT.items():
    if v >= 2:
        ans += v * (v - 1) // 2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import collections
from collections import Counter
# from collections import deque
# from collections import defaultdict
import itertools
# from itertools import accumulate
# from itertools import permutations
# from itertools import combinations
# from itertools import takewhile
from itertools import compress
# import functools
# from functools import reduce
import math
# from math import gcd
# from math import inf
# from math import ceil
# from math import floor
# from math import log10
# from math import log2
# from math import log
from math import factorial

# import re

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

B = list(itertools.accumulate(A))

ans = 0
for l in range(N):
    for r in range(l, N):
        t = B[r] - (B[l - 1] if l - 1 >=0 else 0)
        if t % M == 0:
            ans += 1

print(ans)


Fixed submission:
import sys
import collections
from collections import Counter
# from collections import deque
# from collections import defaultdict
import itertools
# from itertools import accumulate
# from itertools import permutations
# from itertools import combinations
# from itertools import takewhile
from itertools import compress
import functools
# from functools import reduce
import math
# from math import gcd
# from math import inf
# from math import ceil
# from math import floor
# from math import log10
# from math import log2
# from math import log
from math import factorial

# import re

input = sys.stdin.readline

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

B = list(itertools.accumulate(A))
C = [0] + [x % M for x in B]

ans = 0

CNT = collections.Counter(C)

for k, v in CNT.items():
    if v >= 2:
        ans += v * (v - 1) // 2

print(ans)