#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> a(N + 1);
  for (int i = 1; i <= N; i++) cin >> a[i];
  vector<long long> s;
  s.push_back(0);
  for (int i = 1; i <= N; i++) s.push_back(s[i - 1] + a[i]);
  vector<long long> fac{1};
  for (int i = 1; i < 1000; i++) fac.push_back(fac[i - 1] * i);
  fac[0] = 0;
  map<int, int> mp;
  for (int i = 0; i <= N; i++) {
    mp[s[i]]++;
  }
  int res = 0;
  for (auto i = mp.begin(); i != mp.end(); ++i) {
    res += fac[i->second - 1];
  }
  cout << res << endl;
}
