#include <bits/stdc++.h>
using namespace std;
int compare_int(const void *a, const void *b) { return *(int *)a - *(int *)b; }
int factorial(int x) {
  int ans = x;
  for (int i = 1; i < x; i++) {
    ans = ans * i;
  }
  return ans;
}
int main() {
  int a;
  int i;
  int *data;
  scanf("%d", &a);
  a = a + 1;
  data = (int *)malloc(a * sizeof(int));
  data[0] = 0;
  cin >> data[1];
  for (i = 2; i < a; i++) {
    cin >> data[i];
    data[i] = data[i] + data[i - 1];
  }
  map<int, int> val_counter{};
  qsort(data, a, sizeof(int), compare_int);
  if (data[0] == data[1]) {
    val_counter[data[0]] = 1;
  }
  for (i = 2; i < a; i++) {
    if (data[i - 1] == data[i]) {
      if (data[i - 2] == data[i]) {
        val_counter[data[i]] = val_counter[data[i]] + 1;
      } else {
        val_counter[data[i]] = 1;
      }
    }
  }
  int ans = 0;
  for (auto iter = val_counter.begin(); iter != val_counter.end(); ++iter) {
    ans = ans + factorial(iter->second);
  }
  printf("%d\n", ans);
  return 0;
}
