Buggy python submission (verdict: Time Limit Exceeded):
def solve(string):
    n, m, *a = map(int, string.split())
    for i in range(1, n):
        a[i] += a[i - 1]
    a=[0]+a
    ans = 0
    for i in range(1,n+1):
        for j in range(i):
            if (a[i]-a[j])%m==0:
                ans+=1
    return str(ans)


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))


Fixed submission:
from collections import defaultdict


def solve(string):
    n, m, *a = map(int, string.split())
    for i in range(1, n):
        a[i] += a[i - 1]

    d = defaultdict(int)
    for i in range(n):
        d[a[i] % m] += 1
    ans = d[0]
    for v in d.values():
        ans += v * (v - 1) // 2
    return str(ans)


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Buggy python submission (verdict: Time Limit Exceeded):
def solve(string):
    n, m, *a = map(int, string.split())
    for i in range(1, n):
        a[i] += a[i - 1]
    a=[0]+a
    ans = 0
    for i in range(1,n+1):
        for j in range(i):
            if (a[i]-a[j])%m==0:
                ans+=1
    return str(ans)


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))


Fixed submission:
from collections import defaultdict


def solve(string):
    n, m, *a = map(int, string.split())
    for i in range(1, n):
        a[i] += a[i - 1]

    d = defaultdict(int)
    for i in range(n):
        d[a[i] % m] += 1
    ans = d[0]
    for v in d.values():
        ans += v * (v - 1) // 2
    return str(ans)


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Buggy python submission (verdict: Runtime Error):
def solve(string):
    n, m, *a = map(int, string.split())
    for i in range(1, n):
        a[i] += a[i - 1]
    l = [0] * m
    for i in range(n):
        l[a[i] % m] += 1
    ans = l[0]
    for i in range(m):
        ans += l[i] * (l[i] - 1) // 2
    return str(ans)


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))


Fixed submission:
from collections import defaultdict


def solve(string):
    n, m, *a = map(int, string.split())
    for i in range(1, n):
        a[i] += a[i - 1]

    d = defaultdict(int)
    for i in range(n):
        d[a[i] % m] += 1
    ans = d[0]
    for v in d.values():
        ans += v * (v - 1) // 2
    return str(ans)


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Buggy python submission (verdict: Runtime Error):
def solve(string):
    n, m, *a = map(int, string.split())
    for i in range(1, n):
        a[i] += a[i - 1]
    l = [0] * m
    print(a)
    for i in range(n):
        l[a[i] % m] += 1
    ans = l[0]
    for i in range(m):
        ans += l[i] * (l[i] - 1) // 2
    return str(ans)


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))


Fixed submission:
from collections import defaultdict


def solve(string):
    n, m, *a = map(int, string.split())
    for i in range(1, n):
        a[i] += a[i - 1]

    d = defaultdict(int)
    for i in range(n):
        d[a[i] % m] += 1
    ans = d[0]
    for v in d.values():
        ans += v * (v - 1) // 2
    return str(ans)


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))