#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<long long> A(N + 1);
  set<pair<long long, int>> s;
  set<pair<int, int>> ans;
  for (int n = 1; n <= N; ++n) {
    cin >> A[n];
  }
  s.insert({0, 0});
  for (int n = 1; n <= N; ++n) {
    A[n] += A[n - 1];
    auto it2 = s.upper_bound({A[n], N + N});
    it2--;
    if (it2->first == A[n]) {
      ans.insert({n, (it2->second) + 1});
    }
    s.insert({A[n], n});
  }
  long long ret = 0;
  int last_start = 1;
  for (auto it = ans.begin(); it != ans.end(); ++it) {
    for (; last_start <= it->second; ++last_start) {
      ret += it->first - last_start;
    }
  }
  for (; last_start <= N; ++last_start) {
    ret += N - last_start + 1;
  }
  cout << ret;
  return 0;
}
