#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
int a[maxn], cnt[maxn];
long long pre[maxn], jie[maxn];
void init() {
  jie[0] = 0;
  jie[1] = 1;
  for (int i = 2; i < maxn; ++i) jie[i] = i * jie[i - 1];
}
int main() {
  init();
  int n;
  while (cin >> n) {
    long long ans = 0;
    set<int> st;
    memset(pre, 0, sizeof(pre));
    memset(cnt, 0, sizeof(cnt));
    for (int i = 1; i <= n; ++i) {
      cin >> a[i];
      pre[i] = a[i] + pre[i - 1];
      cnt[pre[i]]++;
    }
    for (int i = 1; i <= n; ++i) st.insert(pre[i]);
    set<int>::iterator it = st.begin();
    for (; it != st.end(); ++it) {
      if (*it == 0)
        ans += jie[cnt[0]];
      else
        ans += jie[cnt[*it] - 1];
    }
    cout << ans << endl;
  }
  return 0;
}
