#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int main() {
  long long sum[200001];
  map<long long, long long> cnt;
  sum[0] = 0LL;
  long long N;
  cin >> N;
  unsigned long long ans = 0;
  unsigned long long fact[200001];
  fact[0] = 1LL;
  for (unsigned long long i = 1; i <= N; i++) fact[i] = i * fact[i - 1];
  cnt[0] = 1;
  for (int i = 1; i <= N; i++) {
    long long A;
    cin >> A;
    sum[i] = sum[i - 1] + A;
    cnt[sum[i]]++;
  }
  for (auto it = cnt.begin(); it != cnt.end(); ++it) {
    if (it->second <= 1) continue;
    ans += fact[it->second - 1];
  }
  cout << ans << endl;
  return 0;
}
