#include <bits/stdc++.h>
using namespace std;
long long func(long long x) {
  long long tmp1 = 1, tmp2 = 1;
  for (long long i = 1; i <= x - 2; i++) {
    tmp1 *= i;
    tmp2 *= i;
  }
  tmp1 *= (x - 1) * x;
  return tmp1 / (2 * tmp2);
}
int main() {
  int n;
  cin >> n;
  vector<long long> a(n + 1, 0);
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    a[i] = x + a[i - 1];
  }
  sort(a.begin(), a.end());
  long long zero = 0;
  for (long long i = 1; i <= n; i++) {
    if (a[i] == 0) {
      zero++;
    } else {
      break;
    }
  }
  long long ans = zero;
  if (zero > 1) {
    ans += func(zero);
  }
  long long i = zero + 1;
  while (i <= n) {
    long long tmp = a[i], cnt = 1;
    long long j = i + 1;
    while (true) {
      if (a[j] != tmp || j > n) {
        break;
      } else {
        cnt++;
      }
      j++;
    }
    if (cnt > 1) {
      ans += func(cnt);
    }
    i = j;
  }
  cout << ans << endl;
  return 0;
}
