#include <bits/stdc++.h>
void quicksort(long long int *s, int n) {
  int i, j, l, r, pivot, tmp, top = 2;
  int stack[200001];
  stack[0] = 0;
  stack[1] = n;
  while (top > 0) {
    top -= 2;
    i = l = stack[top];
    j = r = stack[top + 1];
    pivot = s[i];
    while (i <= j) {
      while (s[i] < pivot && i < r) i++;
      while (s[j] > pivot && j > l) j--;
      if (i <= j) {
        tmp = s[i];
        s[i] = s[j];
        s[j] = tmp;
        i++;
        j--;
      }
    }
    if (j > l) {
      stack[top] = l;
      stack[top + 1] = j;
      top += 2;
    }
    if (i < r) {
      stack[top] = i;
      stack[top + 1] = r;
      top += 2;
    }
  }
}
int main(void) {
  int n, i, tmp, n2, j;
  long long int s[200001];
  scanf("%d", &n);
  s[0] = 0;
  for (i = 0; i < n; i++) {
    scanf("%d", &tmp);
    s[i + 1] = s[i] + tmp;
  }
  quicksort(s, n);
  n2 = 0;
  tmp = 1;
  for (i = 1; i <= n; i++) {
    if (s[i] == s[i - 1]) {
      tmp++;
    } else {
      if (tmp > 1) {
        s[n2] = tmp;
        n2++;
        tmp = 1;
      }
    }
  }
  if (tmp > 1) {
    s[n2] = tmp;
    n2++;
  }
  quicksort(s, n2 - 1);
  tmp = 0;
  if (n2 > 0) {
    n = 1;
    for (i = 1; i < s[0]; i++) n *= i;
    tmp += n;
    for (i = 1; i < n2; i++) {
      if (s[i - 1] == s[i]) {
        tmp += n;
      } else {
        for (j = s[i - 1]; j < s[i]; j++) n *= j;
        tmp += n;
      }
    }
  }
  printf("%d\n", tmp);
  return 0;
}
