#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll f(ll n) {
  if (n > 0)
    return n * f(n - 1);
  else
    return 1;
}
int main() {
  ll N, x, cnt = 0, sum = 0;
  cin >> N;
  vector<ll> a(N + 1);
  a[0] = 0;
  for (ll i = 1; i <= N; i++) {
    cin >> x;
    a[i] = a[i - 1] + x;
  }
  sort(a.begin(), a.end());
  for (ll i = 0; i < N; i++) {
    if (a[i] == a[i + 1])
      sum++;
    else {
      if (sum > 0) cnt += f(sum);
      sum = 0;
    }
  }
  if (sum > 0) cnt += f(sum);
  cout << cnt << endl;
  return 0;
}
