#include <bits/stdc++.h>
using namespace std;
int main() {
  int n = 0;
  cin >> n;
  vector<long long> a;
  a.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> ends;
  ends.resize(n);
  int i = 0;
  while (i < n) {
    int j = i + 1;
    long long sum = a[i];
    while (j < n && sum != 0) {
      sum += a[j];
      j++;
    }
    if (sum == 0) {
      ends[i] = j - 1;
    } else {
      ends[i] = -1;
    }
    i = i + 1;
  }
  vector<int> res;
  res.resize(n);
  for (int i = n - 1; i >= 0; i--) {
    if (ends[i] == -1) {
      res[i] = 0;
    } else {
      res[i] = res[ends[i] + 1] + 1;
    }
  }
  int result = 0;
  for (int i = 0; i < n; i++) {
    result += res[i];
  }
  cout << result;
  return 0;
}
