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: #include <algorithm>
  #include <climits>
  #include <cmath>
  #include <cstdio>
  #include <cstdlib>
  #include <iomanip>
  #include <iostream>
  #include <string>
  #include <vector>
  
  typedef long long ll;
  using namespace std;
  
  
  int main() {
      int n = 0;
      cin >> n;
      vector<ll> a(n);
      ll buf = 0;
      for (int i=0; i<n; i++) {
          if (i == 0) {
              a.at(i) = buf;
          }
          else {
              a.at(i) = buf + a.at(i-1);
          }
      }
      sort(a.begin(), a.end());
      int count = 1;
      ll ans = 0;
      for (int i=1; i<n; i++) {
          if (a.at(i) != a.at(i-1)) {
              ans += (count+1)*count/2;
              count = 1;
          }
          else {
              count++;
          }
      }
      ans += (count+1)*count/2;
      cout << ans << endl;
      return 0;
  }
  
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."}]