#include <bits/stdc++.h>
using namespace std;
long long int bikkuri(int u) {
  if (u == 0) return 0;
  long long int a = 1;
  for (int i = 1; i <= u; i++) {
    a *= i;
  }
  return a;
}
int main() {
  int N;
  cin >> N;
  vector<long long int> S(N + 1, 0);
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    S[i + 1] = S[i] + a;
  }
  sort(S.begin(), S.end());
  long long int ans = 0;
  int i = 0;
  while (i < N) {
    int cnt = 0;
    int j = i + 1;
    while (j <= N && S[i] == S[j]) {
      cnt++;
      j++;
    }
    ans += bikkuri(cnt);
    i = j;
  }
  cout << ans << endl;
}
