#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
int facc(int m) {
  int nu = m;
  if (nu == 0 || nu == 1) return 1;
  int ret = 1;
  while (1) {
    ret *= nu;
    --nu;
    if (nu == 1) break;
  }
  return ret;
}
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> s(n + 1);
  s[0] = 0;
  for (int i = 1; i < (n + 1); ++i) {
    int a;
    cin >> a;
    s[i] = s[i - 1] + a;
  }
  sort(s.begin(), s.end());
  map<int, int> num;
  for (int i = 0; i < (n + 1); ++i) {
    ++num[s[i]];
  }
  int res = 0;
  for (auto iter = num.begin(); iter != num.end(); ++iter) {
    int m = iter->second;
    if (m > 1) res += facc(m - 1);
  }
  cout << res << endl;
  return 0;
}
