#include <bits/stdc++.h>
using namespace std;
size_t GetNumberOfCombination(vector<int> A) {
  vector<array<size_t, 2>> sumVec;
  for (size_t i = 0; i < A.size(); i++) {
    int sum = A.at(i);
    size_t j = i + 1;
    for (; j < A.size(); j++) {
      sum += A.at(j);
      if (sum == 0) break;
    }
    if (sum == 0) sumVec.push_back(array<size_t, 2>{i, j});
  }
  map<size_t, size_t> combination;
  set<size_t> used;
  for (auto v : sumVec) {
    if (used.count(v[0])) continue;
    size_t nchain = 1;
    size_t last = v[1];
    used.insert(v[0]);
    while (last + 1 < sumVec.size()) {
      nchain++;
      used.insert(last + 1);
      last = sumVec.at(last + 1)[1];
    }
    if (combination.count(nchain) == 0) combination[nchain] = 0;
    combination[nchain]++;
  }
  size_t n = 0;
  for (auto c : combination) {
    n += c.first * (c.first + 1) / 2 * c.second;
  }
  return n;
}
int main() {
  size_t N;
  cin >> N;
  int ai;
  vector<int> A;
  for (size_t i = 0; i < N; i++) {
    cin >> ai;
    A.push_back(ai);
  }
  auto n = GetNumberOfCombination(A);
  cout << n << endl;
  return 0;
}
