#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  map<long long int, int> m;
  m[0] = -1;
  long long int cuml = 0;
  vector<pair<int, int> > bads;
  for (int i = 0; i < n; i++) {
    long long int inp;
    cin >> inp;
    cuml += inp;
    if (m.find(cuml) != m.end()) {
      bads.push_back({m[cuml] + 1, i});
    }
    m[cuml] = i;
  }
  long long int total_subarrays = (n * (n + 1)) / 2;
  if (bads.empty()) {
    cout << total_subarrays << endl;
    return 0;
  }
  sort(bads.rbegin(), bads.rend());
  vector<pair<int, int> > bads_unique;
  bads_unique.push_back(bads[0]);
  int last_insert = 0;
  for (int i = 1; i < bads.size(); i++) {
    if (bads[i].first < bads[last_insert].first &&
        bads[last_insert].second < bads[i].second) {
      continue;
    }
    bads_unique.push_back(bads[i]);
    last_insert = i;
  }
  sort(bads_unique.begin(), bads_unique.end());
  long long int bad_subarrays = 0;
  for (int i = 0; i < bads_unique.size(); i++) {
    long long int forward_space = bads_unique[i].first;
    long long int backward_space;
    if (i == bads_unique.size() - 1) {
      backward_space = n - bads_unique[i].second - 1;
    } else {
      backward_space = bads_unique[i + 1].second - bads_unique[i].second - 1;
    }
    long long int total_space = (forward_space + 1) * (backward_space + 1);
    bad_subarrays += total_space;
  }
  cout << total_subarrays - bad_subarrays << endl;
}
