Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0] -q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    return [w[0],w[1]]

#　aの逆元を求める
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m

def combination(m,k):
    res = 1
    for i in range(1,m+1):
        res = res*i%(10**9+7)
    for i in range(1,k+1):
        res = res*mod_inv(i,10**9+7)
    for i in range(1,m-k+1):
        res = res*mod_inv(i,10**9+7)
    return res%(10**9+7)

def main():
    n = int(input())
    ls = [int(x) for x in input().split()]
    cumsum = [0]*(n+1)
    for i in range(1,n+1):
        cumsum[i] = cumsum[i-1]+ls[i-1]
    cnt = defaultdict(int)
    for i in cumsum:
        cnt[i] +=1
    ans = 0
    for i in cnt.values():
        if i==1:
            continue
        ans += combination(i,2)
    print(ans)



if __name__ == '__main__':
    main()

Fixed submission:
from collections import defaultdict
def main():
    n = int(input())
    ls = [int(x) for x in input().split()]
    cumsum = [0]*(n+1)
    for i in range(1,n+1):
        cumsum[i] = cumsum[i-1]+ls[i-1]
    cnt = defaultdict(int)
    for i in cumsum:
        cnt[i] +=1
    ans = 0
    for i in cnt.values():
        if i==1:
            continue
        ans += int(i*(i-1)/2)
    print(ans)



if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0] -q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    return [w[0],w[1]]

#　aの逆元を求める
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m

def combination(m,k):
    res = 1
    for i in range(1,m+1):
        res = res*i%(10**9+7)
    for i in range(1,k+1):
        res = res*mod_inv(i,10**9+7)
    for i in range(1,m-k+1):
        res = res*mod_inv(i,10**9+7)
    return res%(10**9+7)

def main():
    n = int(input())
    ls = [int(x) for x in input().split()]
    cumsum = [0]*(n+1)
    for i in range(1,n+1):
        cumsum[i] = cumsum[i-1]+ls[i-1]
    cnt = defaultdict(int)
    for i in cumsum:
        cnt[i] +=1
    ans = 0
    for i in cnt.values():
        if i==1:
            pass
        else:
            ans += combination(i,2)
    print(ans)



if __name__ == '__main__':
    main()

Fixed submission:
from collections import defaultdict
def main():
    n = int(input())
    ls = [int(x) for x in input().split()]
    cumsum = [0]*(n+1)
    for i in range(1,n+1):
        cumsum[i] = cumsum[i-1]+ls[i-1]
    cnt = defaultdict(int)
    for i in cumsum:
        cnt[i] +=1
    ans = 0
    for i in cnt.values():
        if i==1:
            continue
        ans += int(i*(i-1)/2)
    print(ans)



if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0] -q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    return [w[0],w[1]]

#　aの逆元を求める
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m

def combination(m,k):
    res = 1
    for i in range(1,m+1):
        res = res*i%(10**9+7)
    for i in range(1,k+1):
        res = res*mod_inv(i,10**9+7)
    for i in range(1,m-k+1):
        res = res*mod_inv(i,10**9+7)
    return res%(10**9+7)

def main():
    n = int(input())
    ls = [int(x) for x in input().split()]
    cumsum = [0]*(n+1)
    for i in range(1,n+1):
        cumsum[i] = cumsum[i-1]+ls[i-1]
    cnt = defaultdict(int)
    for i in cumsum:
        cnt[i] +=1
    ans = 0
    for i in cnt.values():
        if i==1:
            pass
        else:
            ans += combination(i,2)
    print(ans)



if __name__ == '__main__':
    main()

Fixed submission:
from collections import defaultdict
def main():
    n = int(input())
    ls = [int(x) for x in input().split()]
    cumsum = [0]*(n+1)
    for i in range(1,n+1):
        cumsum[i] = cumsum[i-1]+ls[i-1]
    cnt = defaultdict(int)
    for i in cumsum:
        cnt[i] +=1
    ans = 0
    for i in cnt.values():
        if i==1:
            continue
        ans += int(i*(i-1)/2)
    print(ans)



if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
from collections import defaultdict
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0] -q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    return [w[0],w[1]]

#　aの逆元を求める
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m

def combination(m,k):
    res = 1
    for i in range(1,m+1):
        res = res*i%(10**9+7)
    for i in range(1,k+1):
        res = res*mod_inv(i,10**9+7)
    for i in range(1,m-k+1):
        res = res*mod_inv(i,10**9+7)
    return res%(10**9+7)

def main():
    n = int(input())
    ls = [int(x) for x in input().split()]
    ls.insert(0,0)
    cumsum = np.cumsum(ls)
    cnt = defaultdict(int)
    for i in cumsum:
        cnt[i] +=1
    ans = 0
    for i in cnt.values():
        if i==1:
            pass
        else:
            ans += combination(i,2)
    print(ans)



if __name__ == '__main__':
    main()

Fixed submission:
from collections import defaultdict
def main():
    n = int(input())
    ls = [int(x) for x in input().split()]
    cumsum = [0]*(n+1)
    for i in range(1,n+1):
        cumsum[i] = cumsum[i-1]+ls[i-1]
    cnt = defaultdict(int)
    for i in cumsum:
        cnt[i] +=1
    ans = 0
    for i in cnt.values():
        if i==1:
            continue
        ans += int(i*(i-1)/2)
    print(ans)



if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import numpy as np
from collections import defaultdict
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0] -q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    return [w[0],w[1]]

#　aの逆元を求める
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m

def combination(m,k):
    res = 1
    for i in range(1,m+1):
        res = res*i%(10**9+7)
    for i in range(1,k+1):
        res = res*mod_inv(i,10**9+7)
    for i in range(1,m-k+1):
        res = res*mod_inv(i,10**9+7)
    return res%(10**9+7)

def main():
    n = int(input())
    ls = [int(x) for x in input().split()]
    ls.insert(0,0)
    cumsum = np.cumsum(ls)
    cnt = defaultdict(int)
    for i in cumsum:
        cnt[i] +=1
    ans = 0
    for i in cnt.values():
        if i==1:
            pass
        else:
            ans += combination(i,2)
    print(ans)



if __name__ == '__main__':
    main()

Fixed submission:
from collections import defaultdict
def main():
    n = int(input())
    ls = [int(x) for x in input().split()]
    cumsum = [0]*(n+1)
    for i in range(1,n+1):
        cumsum[i] = cumsum[i-1]+ls[i-1]
    cnt = defaultdict(int)
    for i in cumsum:
        cnt[i] +=1
    ans = 0
    for i in cnt.values():
        if i==1:
            continue
        ans += int(i*(i-1)/2)
    print(ans)



if __name__ == '__main__':
    main()