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