Buggy python submission (verdict: Runtime Error):
import math

N = int(input())

a = list(map(int, input().split()))
b = [a[0] for i in range(N)]

for i in range(1, N):
    b[i] = b[i-1] + a[i]
    
b.sort()
c = 1
ans = 0

def P(n, r):
    return math.factorial(n)//math.factorial(n-r)   

def C(n, r):
    return P(n, r)//math.factorial(r)

for i in range(1, N):
    if b[i]==b[i-1]:
        c = c+1
    else:
        if c>1:
            ans = ans + C(c, 2)
        if b[i-1]==0:
            ans = ans + c
        c=1
else:
    if c>1:
        ans = ans + C(c, 2)
    if b[i-1]==0:
        ans = ans + c
        
print(ans)

Fixed submission:
import math

N = int(input())

a = list(map(int, input().split()))
b = [a[0] for i in range(N)]

for i in range(1, N):
    b[i] = b[i-1] + a[i]
    
b.sort()
c = 1
ans = 0

def P(n, r):
    return math.factorial(n)//math.factorial(n-r)   

def C(n, r):
    return P(n, r)//math.factorial(r)

if N==1:
    if b[0]==0:
        print(1)
    else:
        print(0)
else:
    for i in range(1, N):
        if b[i]==b[i-1]:
            c = c+1
        else:
            if c>1:
                ans = ans + C(c, 2)
            if b[i-1]==0:
                ans = ans + c
            c=1
    else:
        if c>1:
            ans = ans + C(c, 2)
        if b[i-1]==0:
            ans = ans + c
    
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def P(x):
    ans=1
    for i in range(x):
        ans=ans*(i+1)
    
    return(ans)

def comb(n, r):
    return P(n)//(P(n - r)*P(r))

n = int(input())
a=list(map(int,input().split()))

c=[0]*(n+1)

c[0]=a[0]

for i in range(1,n):
    c[i]=c[i-1]+a[i]


c.sort()

#print(c)

now=c[0]
t=1
ans=0

for i in range(1,n+1):
    if c[i]==now:
        t+=1
    else:
        now=c[i]
        if t>1:
            ans+=comb(t,2)
        t=1
else:
    now=c[i]
    if t>1:
        ans+=comb(t,2)
    
print(ans)


Fixed submission:
import math

N = int(input())

a = list(map(int, input().split()))
b = [a[0] for i in range(N)]

for i in range(1, N):
    b[i] = b[i-1] + a[i]
    
b.sort()
c = 1
ans = 0

def P(n, r):
    return math.factorial(n)//math.factorial(n-r)   

def C(n, r):
    return P(n, r)//math.factorial(r)

if N==1:
    if b[0]==0:
        print(1)
    else:
        print(0)
else:
    for i in range(1, N):
        if b[i]==b[i-1]:
            c = c+1
        else:
            if c>1:
                ans = ans + C(c, 2)
            if b[i-1]==0:
                ans = ans + c
            c=1
    else:
        if c>1:
            ans = ans + C(c, 2)
        if b[i-1]==0:
            ans = ans + c
    
    print(ans)

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

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


#
#for i in range(N):
#    Sum[i] = Sum[i-1] + A[i]

count = 0
S = np.zeros(N)


for i in range(N):
    for j in range(i+1):
        S[j] = S[j] + A[i]
        if S[j] == 0:
            count += 1
#    Sum[i] = A[i]
#    S = A[i]
#    if S == 0:
#        count += 1
#    for j in range(i+1, N):
#        S += A[j]
#        if S == 0:
#            count += 1
            
print(count)

Fixed submission:
import math

N = int(input())

a = list(map(int, input().split()))
b = [a[0] for i in range(N)]

for i in range(1, N):
    b[i] = b[i-1] + a[i]
    
b.sort()
c = 1
ans = 0

def P(n, r):
    return math.factorial(n)//math.factorial(n-r)   

def C(n, r):
    return P(n, r)//math.factorial(r)

if N==1:
    if b[0]==0:
        print(1)
    else:
        print(0)
else:
    for i in range(1, N):
        if b[i]==b[i-1]:
            c = c+1
        else:
            if c>1:
                ans = ans + C(c, 2)
            if b[i-1]==0:
                ans = ans + c
            c=1
    else:
        if c>1:
            ans = ans + C(c, 2)
        if b[i-1]==0:
            ans = ans + c
    
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

#Sum = np.zeros(N)
#
#for i in range(N):
#    Sum[i] = Sum[i-1] + A[i]

count = 0



for i in range(N):
    S = 0
    S = A[i]
    if S == 0:
        count += 1
    for j in range(i+1, N):
        S += A[j]
        if S == 0:
            count += 1
            
print(count)

Fixed submission:
import math

N = int(input())

a = list(map(int, input().split()))
b = [a[0] for i in range(N)]

for i in range(1, N):
    b[i] = b[i-1] + a[i]
    
b.sort()
c = 1
ans = 0

def P(n, r):
    return math.factorial(n)//math.factorial(n-r)   

def C(n, r):
    return P(n, r)//math.factorial(r)

if N==1:
    if b[0]==0:
        print(1)
    else:
        print(0)
else:
    for i in range(1, N):
        if b[i]==b[i-1]:
            c = c+1
        else:
            if c>1:
                ans = ans + C(c, 2)
            if b[i-1]==0:
                ans = ans + c
            c=1
    else:
        if c>1:
            ans = ans + C(c, 2)
        if b[i-1]==0:
            ans = ans + c
    
    print(ans)