output_description: Find the number of the non-empty contiguous subsequences of A whose sum is 0.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
      A_1 A_2 ... A_N
attempt: from collections import Counter
  
  
  class ModFactorial:
      """
      階乗, 組み合わせ, 順列の計算
      """
  
      def __init__(self, n, MOD=10**9 + 7):
          kaijo = [0] * (n + 10)
          gyaku = [0] * (n + 10)
  
          kaijo[0] = 1
          kaijo[1] = 1
          for i in range(2, len(kaijo)):
              kaijo[i] = (i * kaijo[i - 1]) % MOD
          gyaku[0] = 1
          gyaku[1] = 1
          for i in range(2, len(gyaku)):
              gyaku[i] = pow(kaijo[i], MOD - 2, MOD)
          self.kaijo = kaijo
          self.gyaku = gyaku
          self.MOD = MOD
  
      def nCm(self, n, m):
          return (self.kaijo[n] * self.gyaku[n - m] * self.gyaku[m]) % self.MOD
  
      def nPm(self, n, m):
          return (self.kaijo[n] * self.gyaku[n - m]) % self.MOD
  
      def factorial(self, n):
          return self.kaijo[n]
  
  
  N = [int(_) for _ in input().split()][0]
  a = [int(_) for _ in input().split()]
  
  s = [0] * (len(a) + 1)
  for i in range(len(a)):
      s[i + 1] = s[i] + a[i]
  
  
  c = Counter()
  
  for i in range(len(s)):
      c[s[i]] += 1
  
  mod = ModFactorial(len(s))
  
  ans = 0
  for cnt in c.values():
      if cnt < 2:
          continue
  
      ans += mod.nCm(cnt, 2)
  print(ans)
  
problem_description: Statement
  
  We have an integer sequence A, whose length is N.
  
  Find the number of the non-empty **contiguous** subsequences of A whose sums
  are 0. Note that we are counting **the ways to take out subsequences**. That
  is, even if the contents of some two subsequences are the same, they are
  counted individually if they are taken from different positions.
samples: [{"input": "6\n    1 3 -4 2 2 -2", "output": "3\n    \n\nThere are three contiguous subsequences whose sums are 0: (1,3,-4), (-4,2,2)\nand (2,-2).\n\n* * *"}, {"input": "7\n    1 -1 1 -1 1 -1 1", "output": "12\n    \n\nIn this case, some subsequences that have the same contents but are taken from\ndifferent positions are counted individually. For example, three occurrences\nof (1, -1) are counted.\n\n* * *"}, {"input": "5\n    1 -2 3 -4 5", "output": "0\n    \n\nThere are no contiguous subsequences whose sums are 0."}]