Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
suma = [0 for i in range(n)]
for i in range(n):
    suma[i] = suma[i-1] + a[i]
ans = 0
for i in range(n):
    if suma[i] == 0:
        ans += 1
    for j in range(i):
        if suma[i]-suma[j] == 0:
            ans += 1
print(ans)


Fixed submission:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))

ans = 0
sum = [0 for i in range(n+1)]

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

count = Counter(sum)

for values in count.values():
    if values >= 2:
        ans += values * (values-1) // 2

print(ans)

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

ans = 0
sum = [0 for i in range(n+1)]

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

sum = sorted(sum)

for i in range(n):
    tmp = sum[i]
    for j in range(i+1, n+1):
        if tmp == sum[j]:
            ans += 1
        else:
            break

print(ans)

Fixed submission:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))

ans = 0
sum = [0 for i in range(n+1)]

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

count = Counter(sum)

for values in count.values():
    if values >= 2:
        ans += values * (values-1) // 2

print(ans)

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

ans = 0
sum = [0 for i in range(n+1)]

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

sum = sorted(sum)

for i in range(n):
    tmp = sum[i]
    for j in range(i, n+1):
        if i != j and tmp == sum[j]:
            ans += 1

print(ans)

Fixed submission:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))

ans = 0
sum = [0 for i in range(n+1)]

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

count = Counter(sum)

for values in count.values():
    if values >= 2:
        ans += values * (values-1) // 2

print(ans)

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

ans = 0
suma0 = [0 for i in range(n)]

if a[0] == 0:
    ans+=1
else:
    suma0[0] = a[0]

for i in range(1, n):
    suma0[i] = suma0[i-1] + a[i]
    if suma0[i] == 0:
        ans += 1

for i in range(1,n):
    for j in range(i, n):
        suma0[j] -= a[i-1]
        if suma0[j] == 0:
            ans += 1

print(ans)

Fixed submission:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))

ans = 0
sum = [0 for i in range(n+1)]

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

count = Counter(sum)

for values in count.values():
    if values >= 2:
        ans += values * (values-1) // 2

print(ans)

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

ans = 0

for i in range(n):
    sum = a[i]
    if sum == 0:
        ans += 1
    for j in range(i+1, n):
        sum += a[j]
        if sum == 0:
            ans += 1

print(ans)

Fixed submission:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))

ans = 0
sum = [0 for i in range(n+1)]

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

count = Counter(sum)

for values in count.values():
    if values >= 2:
        ans += values * (values-1) // 2

print(ans)