Buggy python submission (verdict: Time Limit Exceeded):
def calc(value):
    return value*(value-1)//2


n = int(input())
array = [int(x) for x in input().split()]

tmp_sum = 0
sum_array = []

for i in array:
    tmp_sum += i
    sum_array.append(tmp_sum)

sum_dict = {x:sum_array.count(x) for x in set(sum_array)}
if 0 in sum_dict.keys():
    sum_dict[0] += 1

res = 0
for key, value in sum_dict.items():
    if value >= 2:
        res += calc(value)

print(res)



Fixed submission:
n=int(input())
a=list(map(int,input().split()))
ans=0
b=[]
sum=0
for i in range(n):
    sum+=a[i]
    b.append(sum)
b=sorted(b)
b.append(float("inf"))
k=0
for i in range(n):
    if b[i]==b[i+1]:
        k+=1
    else:
        if not k==0:
            ans+=k*(k+1)//2
        k=0
for i in range(n):
    if b[i]==0:
        ans+=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def calc(value):
    return value*(value-1)//2


n = int(input())
array = [int(x) for x in input().split()]

tmp_sum = 0
sum_array = []

for i in array:
    tmp_sum += i
    sum_array.append(tmp_sum)

sum_dict = {x:sum_array.count(x) for x in set(sum_array)}
if 0 in sum_dict.keys():
    sum_dict[0] += 1

res = 0
for key, value in sum_dict.items():
    if value >= 2:
        res += calc(value)

print(res)



Fixed submission:
n=int(input())
a=list(map(int,input().split()))
ans=0
b=[]
sum=0
for i in range(n):
    sum+=a[i]
    b.append(sum)
b=sorted(b)
b.append(float("inf"))
k=0
for i in range(n):
    if b[i]==b[i+1]:
        k+=1
    else:
        if not k==0:
            ans+=k*(k+1)//2
        k=0
for i in range(n):
    if b[i]==0:
        ans+=1
print(ans)

Buggy python submission (verdict: Runtime Error):
def calc(value):
    tmp = 1
    for i in range(1, value+1):
        tmp *= i
    return tmp//2


n = int(input())
array = [int(x) for x in input().split()]

tmp_sum = 0
sum_array = []

for i in array:
    tmp_sum += i
    sum_array.append(tmp_sum)

sum_dict = {x:sum_array.count(x) for x in set(sum_array)}

minus = 0
if sum_array.count(0) == 1:
    sum_dict[0] += 1
else:
    minus = sum_dict[0]

res = 0
for key, value in sum_dict.items():
    if value >= 2:
        res += calc(value)

print(res-minus)



Fixed submission:
n=int(input())
a=list(map(int,input().split()))
ans=0
b=[]
sum=0
for i in range(n):
    sum+=a[i]
    b.append(sum)
b=sorted(b)
b.append(float("inf"))
k=0
for i in range(n):
    if b[i]==b[i+1]:
        k+=1
    else:
        if not k==0:
            ans+=k*(k+1)//2
        k=0
for i in range(n):
    if b[i]==0:
        ans+=1
print(ans)

Buggy python submission (verdict: Runtime Error):
def calc(value):
    tmp = 1
    for i in range(1, value+1):
        tmp *= i
    return tmp//2


n = int(input())
array = [int(x) for x in input().split()]

tmp_sum = 0
sum_array = []

for i in array:
    tmp_sum += i
    sum_array.append(tmp_sum)

sum_dict = {x:sum_array.count(x) for x in set(sum_array)}

minus = 0
if sum_array.count(0) == 1:
    sum_dict[0] += 1
else:
    minus = sum_dict[0]

res = 0
for key, value in sum_dict.items():
    if value >= 2:
        res += calc(value)

print(res-minus)



Fixed submission:
n=int(input())
a=list(map(int,input().split()))
ans=0
b=[]
sum=0
for i in range(n):
    sum+=a[i]
    b.append(sum)
b=sorted(b)
b.append(float("inf"))
k=0
for i in range(n):
    if b[i]==b[i+1]:
        k+=1
    else:
        if not k==0:
            ans+=k*(k+1)//2
        k=0
for i in range(n):
    if b[i]==0:
        ans+=1
print(ans)