#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N;
  long long ans = 0;
  cin >> N;
  vector<long long> A(N);
  set<long long> S;
  map<long long, long long> mp;
  long long sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    sum += A[i];
    S.insert(sum);
    mp[sum]++;
  }
  auto itr = S.begin();
  while (itr != S.end()) {
    if (*itr != 0) {
      mp[*itr]--;
    }
    if (mp[*itr] >= 1) {
      long long c = 1;
      for (int i = 1; i <= mp[*itr]; i++) {
        c *= i;
      }
      ans += c;
    }
    itr++;
  }
  cout << ans << endl;
}
