#include <bits/stdc++.h>
using namespace std;
long long f(long long n) {
  long long r = 1;
  for (long long i = 1; i < n + 1; i++) {
    r *= i;
  }
  if (n == 0) {
    return (0);
  } else {
    return (r);
  }
}
int main() {
  long long n, s = 0, ai;
  cin >> n;
  map<long long, long long> d;
  d[0] = 1;
  for (long long i = 0; i < n; i++) {
    cin >> ai;
    s += ai;
    auto itr = d.find(s);
    if (itr != d.end()) {
      d[s] += 1;
    } else {
      d[s] = 1;
    }
  }
  long long ans = 0;
  for (map<long long, long long>::iterator i = d.begin(); i != d.end(); i++) {
    ans += f((i->second) - 1);
  }
  cout << ans;
}
