Buggy python submission (verdict: Runtime Error):
from math import factorial
import sys
input = sys.stdin.readline
def ncr(n,r):
 if n <= 1:
  return 0
 elif n == 2:
  return 1
 else:
  return  factorial(n) / factorial(r) / factorial(n - r)

n= int(input())
a = list(int(i) for i in input().split())
s = [0]
for i in range(n):
  s.append(s[i]+a[i])
s = sorted(s,reverse =True)
ans = 0
tmp = 1
for i in range(len(s)-1):
  if s[i] == s[i+1]:
   tmp += 1
  else:
   ans += ncr(tmp,2)
   tmp = 1
ans += ncr(tmp,2)
print(int(ans))


Fixed submission:
from math import factorial
import sys
input = sys.stdin.readline
def ncr(n):
 if n <= 1:
  return 0
 elif n == 2:
  return 1
 else:
  return  (factorial(n) // 2) // factorial(n - 2)

n= int(input())
a = list(int(i) for i in input().split())
s = [0]
for i in range(n):
  s.append(s[i]+a[i])
s = sorted(s,reverse =True)
ans = 0
tmp = 1
for i in range(len(s)-1):
  if s[i] == s[i+1]:
   tmp += 1
  else:
   ans += ncr(tmp)
   tmp = 1
ans += ncr(tmp)
print(ans)

Buggy python submission (verdict: Runtime Error):
from math import factorial
import sys
input = sys.stdin.readline
def ncr(n,r):
 if n <= 1:
  return 0
 elif n == 2:
  return 1
 else:
  return  factorial(n) / factorial(r) / factorial(n - r)

n= int(input())
a = list(int(i) for i in input().split())
s = [0]
for i in range(n):
  s.append(s[i]+a[i])
s = sorted(s,reverse =True)
ans = 0
tmp = 1
for i in range(n):
  if s[i] == s[i+1]:
   tmp += 1
  else:
   ans += ncr(tmp,2)
   tmp = 1
ans += ncr(tmp,2)
print(int(ans))


Fixed submission:
from math import factorial
import sys
input = sys.stdin.readline
def ncr(n):
 if n <= 1:
  return 0
 elif n == 2:
  return 1
 else:
  return  (factorial(n) // 2) // factorial(n - 2)

n= int(input())
a = list(int(i) for i in input().split())
s = [0]
for i in range(n):
  s.append(s[i]+a[i])
s = sorted(s,reverse =True)
ans = 0
tmp = 1
for i in range(len(s)-1):
  if s[i] == s[i+1]:
   tmp += 1
  else:
   ans += ncr(tmp)
   tmp = 1
ans += ncr(tmp)
print(ans)

Buggy python submission (verdict: Runtime Error):
from math import factorial
import sys
input = sys.stdin.readline
def ncr(n,r):
 if n <= 1:
  return 0
 else:
  return  factorial(n) / factorial(r) / factorial(n - r)

n= int(input())
a = list(int(i) for i in input().split())
s = [0]
for i in range(n):
  s.append(s[i]+a[i])
s = sorted(s,reverse =True)
ans = 0
tmp = 1
for i in range(n):
  if s[i] == s[i+1]:
   tmp += 1
  else:
   ans += ncr(tmp,2)
   tmp = 1
ans += ncr(tmp,2)
print(int(ans))


Fixed submission:
from math import factorial
import sys
input = sys.stdin.readline
def ncr(n):
 if n <= 1:
  return 0
 elif n == 2:
  return 1
 else:
  return  (factorial(n) // 2) // factorial(n - 2)

n= int(input())
a = list(int(i) for i in input().split())
s = [0]
for i in range(n):
  s.append(s[i]+a[i])
s = sorted(s,reverse =True)
ans = 0
tmp = 1
for i in range(len(s)-1):
  if s[i] == s[i+1]:
   tmp += 1
  else:
   ans += ncr(tmp)
   tmp = 1
ans += ncr(tmp)
print(ans)

Buggy python submission (verdict: Runtime Error):
from math import factorial
import sys
input = sys.stdin.readline
def ncr(n,r):
 if n <= 1:
  return 0
 else:
  return  factorial(n) / factorial(r) / factorial(n - r)

n= int(input())
a = list(int(i) for i in input().split())
s = [0]
for i in range(n):
  s.append(s[i]+a[i])
s = sorted(s,reverse =True)
ans = 0
tmp = 1

for i in range(n+1):
  if s[i-1] == s[i]:
   tmp += 1
  else:
   ans += ncr(tmp,2)
   tmp = 1
ans += ncr(tmp,2)
print(int(ans))


Fixed submission:
from math import factorial
import sys
input = sys.stdin.readline
def ncr(n):
 if n <= 1:
  return 0
 elif n == 2:
  return 1
 else:
  return  (factorial(n) // 2) // factorial(n - 2)

n= int(input())
a = list(int(i) for i in input().split())
s = [0]
for i in range(n):
  s.append(s[i]+a[i])
s = sorted(s,reverse =True)
ans = 0
tmp = 1
for i in range(len(s)-1):
  if s[i] == s[i+1]:
   tmp += 1
  else:
   ans += ncr(tmp)
   tmp = 1
ans += ncr(tmp)
print(ans)

Buggy python submission (verdict: Runtime Error):
from math import factorial
import sys
input = sys.stdin.readline
def ncr(n,r):
 if n == 1:
  return 0
 else:
  return  factorial(n) / factorial(r) / factorial(n - r)

n= int(input())
a = list(int(i) for i in input().split())
s = [0]
for i in range(n):
  s.append(s[i]+a[i])
s = sorted(s,reverse =True)
ans = 0
for i in list(set(s)):
  ans += ncr(s.count(i),2)
print(int(ans))


Fixed submission:
from math import factorial
import sys
input = sys.stdin.readline
def ncr(n):
 if n <= 1:
  return 0
 elif n == 2:
  return 1
 else:
  return  (factorial(n) // 2) // factorial(n - 2)

n= int(input())
a = list(int(i) for i in input().split())
s = [0]
for i in range(n):
  s.append(s[i]+a[i])
s = sorted(s,reverse =True)
ans = 0
tmp = 1
for i in range(len(s)-1):
  if s[i] == s[i+1]:
   tmp += 1
  else:
   ans += ncr(tmp)
   tmp = 1
ans += ncr(tmp)
print(ans)

Buggy python submission (verdict: Runtime Error):
from math import factorial
def ncr(n,r):
 if n == 1:
  return 0
 else:
  return  factorial(n) / factorial(r) / factorial(n - r)

n= int(input())
a = list(int(i) for i in input().split())
s = [0]
for i in range(n):
  s.append(s[i]+a[i])
s = sorted(s,reverse =True)
ans = 0
for i in list(set(s)):
  ans += ncr(s.count(i),2)
print(int(ans))

Fixed submission:
from math import factorial
import sys
input = sys.stdin.readline
def ncr(n):
 if n <= 1:
  return 0
 elif n == 2:
  return 1
 else:
  return  (factorial(n) // 2) // factorial(n - 2)

n= int(input())
a = list(int(i) for i in input().split())
s = [0]
for i in range(n):
  s.append(s[i]+a[i])
s = sorted(s,reverse =True)
ans = 0
tmp = 1
for i in range(len(s)-1):
  if s[i] == s[i+1]:
   tmp += 1
  else:
   ans += ncr(tmp)
   tmp = 1
ans += ncr(tmp)
print(ans)

Buggy python submission (verdict: Runtime Error):
from math import factorial
def ncr(n,r):
  return (factorial(n) // factorial(r) // factorial(n - r))

n= int(input())
a = list(int(i) for i in input().split())
s = [0]
tp = 0
for i in a:
  tp += i
  s.append(tp)
s.sort()
ans = 0
for i in range(n):
  if s[i] == s[i+1]:
    ans += 1
print(ncr(ans,2))

Fixed submission:
from math import factorial
import sys
input = sys.stdin.readline
def ncr(n):
 if n <= 1:
  return 0
 elif n == 2:
  return 1
 else:
  return  (factorial(n) // 2) // factorial(n - 2)

n= int(input())
a = list(int(i) for i in input().split())
s = [0]
for i in range(n):
  s.append(s[i]+a[i])
s = sorted(s,reverse =True)
ans = 0
tmp = 1
for i in range(len(s)-1):
  if s[i] == s[i+1]:
   tmp += 1
  else:
   ans += ncr(tmp)
   tmp = 1
ans += ncr(tmp)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n =int(input())
a = list(int(i) for i in input().split())
ct = 0
for j in range(n):
 a2=[0]
 for i in a: 
  if (a2[-1]+i) == 0:ct += 1
  a2.append(a2[-1]+i)
 a.pop(0)
print(ct)

Fixed submission:
from math import factorial
import sys
input = sys.stdin.readline
def ncr(n):
 if n <= 1:
  return 0
 elif n == 2:
  return 1
 else:
  return  (factorial(n) // 2) // factorial(n - 2)

n= int(input())
a = list(int(i) for i in input().split())
s = [0]
for i in range(n):
  s.append(s[i]+a[i])
s = sorted(s,reverse =True)
ans = 0
tmp = 1
for i in range(len(s)-1):
  if s[i] == s[i+1]:
   tmp += 1
  else:
   ans += ncr(tmp)
   tmp = 1
ans += ncr(tmp)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n =int(input())
a = list(int(i) for i in input().split())
ct = 0
for j in range(n):
 a2=[0]
 for i in a: 
  if (a2[-1]+i) == 0:ct += 1
  a2.append(a2[-1]+i)
 a.pop(0)
print(ct)

Fixed submission:
from math import factorial
import sys
input = sys.stdin.readline
def ncr(n):
 if n <= 1:
  return 0
 elif n == 2:
  return 1
 else:
  return  (factorial(n) // 2) // factorial(n - 2)

n= int(input())
a = list(int(i) for i in input().split())
s = [0]
for i in range(n):
  s.append(s[i]+a[i])
s = sorted(s,reverse =True)
ans = 0
tmp = 1
for i in range(len(s)-1):
  if s[i] == s[i+1]:
   tmp += 1
  else:
   ans += ncr(tmp)
   tmp = 1
ans += ncr(tmp)
print(ans)