#include <bits/stdc++.h>
using namespace std;
long long res = 0;
int main() {
  int n;
  scanf("%d", &n);
  vector<long long> a(n + 1, 0);
  for (int i = 0; i < n; i++) {
    long long t;
    scanf("%lld", &t);
    if (t == 0) res++;
    a[i + 1] = a[i] + t;
  }
  swap(a[0], a.back());
  a.pop_back();
  for (int i = 0; i < a.size(); ++i) {
    if (a[i] == 0 && i == 0) {
      continue;
    } else if (a[i] == 0) {
      res++;
    }
  }
  sort(a.begin(), a.end());
  long long tmp = 0;
  for (int i = 0; i < n - 1; ++i) {
    if (a[i] == a[i + 1]) {
      tmp++;
    } else if (a[i] != a[i + 1]) {
      res += (tmp > 0) ? ((tmp + 1) * tmp) / 2 : 0;
      tmp = 0;
    }
  }
  if (tmp > 0) {
    res += ((tmp + 1) * tmp) / 2;
  }
  printf("%lld\n", res);
}
