#include <bits/stdc++.h>
using namespace std;
using ll = long long;
long long int factorial(int k) {
  long long int sum = 1;
  for (int i = 1; i <= k; ++i) {
    sum *= i;
  }
  return sum;
}
int main() {
  int N;
  cin >> N;
  map<ll, ll> acc_sum;
  ll sum = 0;
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    sum += A;
    acc_sum[sum]++;
  }
  int output = 0;
  for (auto e : acc_sum) {
    if (e.first == 0) output += factorial(e.second);
    if (e.second != 1 && e.first != 0) {
      output += factorial(e.second - 1);
    }
  }
  cout << output << endl;
  return 0;
}
