#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int x, long long int y) {
  return y != 0 ? gcd(y, x % y) : x;
}
long long int lcm(long long int x, long long int y) {
  return x * y / gcd(x, y);
}
long long int factorial(long long int x) {
  return x == 0 ? 1 : x * factorial(x - 1);
}
int main() {
  int i, j, n;
  cin >> n;
  long long a[n], ans = 0, ct = 0, sum = 0;
  for (i = 0; i < n; i++) cin >> a[i];
  long long b[n + 1];
  b[0] = 0;
  b[1] = a[0];
  for (i = 1; i < n; i++) b[i + 1] = b[i] + a[i];
  sort(b, b + n + 1);
  for (i = 0; i < n; i++) {
    if (b[i] == b[i + 1])
      ct++;
    else {
      if (ct > 0) ans += factorial(ct);
      ct = 0;
    }
  }
  if (ct > 0) ans += factorial(ct);
  cout << ans;
  return 0;
}
