#include <bits/stdc++.h>
using namespace std;
unsigned int factorial(unsigned int n) {
  if (n == 0) return 1;
  return n * factorial(n - 1);
}
int main() {
  stringstream ss;
  int N;
  cin >> N;
  int A[N + 1];
  long long sum[N + 1];
  sum[0] = 0;
  cin >> A[1];
  sum[1] = A[1];
  for (int i = 2; i <= N; i++) {
    cin >> A[i];
    sum[i] = sum[i - 1] + A[i];
  }
  int ans = 0;
  sort(sum, sum + N + 1);
  for (int i = 0; i <= N - 1; i++) {
    int k = 1;
    bool same = false;
    while (i + k <= N && sum[i] == sum[i + k]) {
      same = true;
      k++;
    }
    if (same) {
      ans += factorial(k - 1);
      i = i + k - 1;
    }
  }
  cout << ans << endl;
  return 0;
}
