Buggy python submission (verdict: Time Limit Exceeded):
def inpl(): return [int(i) for i in input().split()]

def solve(n,S):
    Ctr = set([])
    for i in range(n+1):
        Ctr = Ctr | set([S[i]])
    Ans = {}
    for i in range(n+1):
        Ans[S[i]] = 0
    for i in range(n+1):
        Ans[S[i]] += 1
    
    ans = 0
    for i in Ctr:
        ans += Ans[i] * (Ans[i] - 1) // 2
    return(ans)

N,M = inpl()
H = inpl()

SumH = [0]
for i in range(N):
    SumH.append((SumH[-1] + H[i]) % M)

print(solve(N,SumH))

Fixed submission:
def inpl(): return [int(i) for i in input().split()]

N,M = inpl()
H = {0: 1}
k = 0
ans = 0
for i in inpl():
    k += i
    t = k % M
    if t not in H:
        H[t] = 0
    H[t] += 1
    
for i in H.values():
   ans += i * (i - 1) // 2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def inpl(): return [int(i) for i in input().split()]

def solve(n,S):
    Ctr = set([])
    for i in range(n+1):
        Ctr = Ctr | set([S[i]])
    Ans = {}
    for i in range(n+1):
        Ans[S[i]] = 0
    for i in range(n+1):
        Ans[S[i]] += 1
    
    ans = 0
    for i in Ctr:
        ans += Ans[i] * (Ans[i] - 1) // 2
    return(ans)

N,M = inpl()
H = inpl()

SumH = [0]
for i in range(N):
    SumH.append((SumH[-1] + H[i]) % M)

print(solve(N,SumH))

Fixed submission:
def inpl(): return [int(i) for i in input().split()]

N,M = inpl()
H = {0: 1}
k = 0
ans = 0
for i in inpl():
    k += i
    t = k % M
    if t not in H:
        H[t] = 0
    H[t] += 1
    
for i in H.values():
   ans += i * (i - 1) // 2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,M = [int(i) for i in input().split()]
H = [int(i) for i in input().split()]
for i in range(N):
    H[i] = H[i]%M
SumH = [0]
for i in range(N):
    SumH.append((SumH[i]+H[i])%M)
Ctr = []
Ans = {}
for i in range(N+1):
    if SumH[i] not in Ctr:
        Ctr.append(SumH[i])
        Ans[SumH[i]] = 1
    else:
        Ans[SumH[i]] += 1
ans = 0
for i in Ctr:
    ans += Ans[i]*(Ans[i]-1)//2
print(ans)


Fixed submission:
def inpl(): return [int(i) for i in input().split()]

N,M = inpl()
H = {0: 1}
k = 0
ans = 0
for i in inpl():
    k += i
    t = k % M
    if t not in H:
        H[t] = 0
    H[t] += 1
    
for i in H.values():
   ans += i * (i - 1) // 2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,M = [int(i) for i in input().split()]
H = [int(i) for i in input().split()]
for i in range(N):
    H[i] = H[i]%M
SumH = [0 for i in range(N+1)] 
for i in range(1,N+1):
    SumH[i] = (SumH[i-1]+H[i-1])%M
Ctr = [-1 for i in range(N+1)]
Ans = [0 for i in range(N+1)]
for i in range(N+1):
    if SumH[i] in Ctr:
        continue
    Ctr[i] = SumH[i]
    Ans[i] = (SumH.count(SumH[i]))
for i in range(N+1):
    Ans[i] = Ans[i]*(Ans[i]-1)//2
print(sum(Ans))

Fixed submission:
def inpl(): return [int(i) for i in input().split()]

N,M = inpl()
H = {0: 1}
k = 0
ans = 0
for i in inpl():
    k += i
    t = k % M
    if t not in H:
        H[t] = 0
    H[t] += 1
    
for i in H.values():
   ans += i * (i - 1) // 2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,M = [int(i) for i in input().split()]
H = [int(i) for i in input().split()]
for i in range(N):
    H[i] = H[i]%M
SumH = [0] 
for i in range(N):
    SumH.append((SumH[i]+H[i])%M)
Ctr = []
Ans = [0 for i in range(N+1)]
for i in range(N+1):
    if SumH[i] in Ctr:
        continue
    Ctr.append(SumH[i])
    Ans[i] = (SumH.count(SumH[i]))
for i in range(N+1):
    Ans[i] = Ans[i]*(Ans[i]-1)//2
print(sum(Ans))

Fixed submission:
def inpl(): return [int(i) for i in input().split()]

N,M = inpl()
H = {0: 1}
k = 0
ans = 0
for i in inpl():
    k += i
    t = k % M
    if t not in H:
        H[t] = 0
    H[t] += 1
    
for i in H.values():
   ans += i * (i - 1) // 2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,M = [int(i) for i in input().split()]
H = [int(i) for i in input().split()]
for i in range(N):
    H[i] = H[i]%M
SumH = [0]
for i in range(N):
    SumH.append((SumH[i]+H[i])%M)
Ctr = []
Ans = []
for i in range(N+1):
    if SumH[i] not in Ctr:
        Ctr.append(SumH[i])
        Ans.append(int((SumH.count(SumH[i]))*(SumH.count(SumH[i])-1)/2))
print(sum(Ans))

Fixed submission:
def inpl(): return [int(i) for i in input().split()]

N,M = inpl()
H = {0: 1}
k = 0
ans = 0
for i in inpl():
    k += i
    t = k % M
    if t not in H:
        H[t] = 0
    H[t] += 1
    
for i in H.values():
   ans += i * (i - 1) // 2

print(ans)