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