#include <bits/stdc++.h>
using namespace std;
int ara[200008];
long long sumA[200008];
unordered_map<long long, int> mp;
long long fac[50];
int main() {
  int n;
  cin >> n;
  fac[0] = 1;
  for (int i = 1; i <= 20; i++) {
    fac[i] = fac[i - 1] * i;
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &ara[i]);
    sumA[i] += sumA[i - 1] + ara[i];
    mp[sumA[i]]++;
  }
  long long ans = 0;
  for (auto x : mp) {
    if (x.first == 0) {
      ans += x.second;
      if (x.second > 1) {
        ans += (fac[x.second - 1] * 2) - 1;
      }
    } else if (x.second > 1) {
      ans += fac[x.second - 1];
    }
  }
  cout << ans << endl;
  return 0;
}
