#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long mypow(long long base, long long exp) {
  long long res = 1;
  while (exp) {
    if (exp & 1) res = (res * base) % mod;
    exp >>= 1, base = (base * base) % mod;
  }
  return res;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long mult(long long a, long long b) {
  if (a < 0) {
    a += mod;
  }
  if (b < 0) {
    b += mod;
  }
  return ((a % mod) * (b % mod)) % mod;
}
long long add(long long a, long long b) {
  if (a < 0) {
    a += mod;
  }
  if (b < 0) {
    b += mod;
  }
  return (a % mod + b % mod) % mod;
}
long long sub(long long a, long long b) {
  if (a < 0) {
    a += mod;
  }
  if (b < 0) {
    b += mod;
  }
  return (a % mod + mod - b % mod) % mod;
}
const long long inf = 1e18;
const int nax = 1e5 + 5;
void SolveTestCase() {
  long long n;
  cin >> n;
  vector<long long> a(n), pref(n);
  map<long long, vector<long long>> idx;
  idx[0].push_back(-1);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    if (i == 0)
      pref[i] = a[i];
    else {
      pref[i] = pref[i - 1] + a[i];
    }
    idx[pref[i]].push_back(i);
  }
  vector<pair<long long, long long>> x;
  auto itr = idx.find(0);
  if (itr != idx.end()) {
    long long i = -1;
    long long j = lower_bound((itr->second).begin(), (itr->second).end(), i) -
                  itr->second.begin();
    if (j + 1 < (long long)itr->second.size()) {
      x.push_back({i + 1, itr->second[j + 1]});
    }
  }
  for (long long i = 0; i < n; i++) {
    auto itr = idx.find(pref[i]);
    if (itr != idx.end()) {
      long long j = lower_bound((itr->second).begin(), (itr->second).end(), i) -
                    itr->second.begin();
      if (j + 1 < (long long)itr->second.size()) {
        x.push_back({i + 1, itr->second[j + 1]});
      }
    }
  }
  long long curr = 0;
  long long m = x.size();
  long long ans = (n * (n + 1)) / 2;
  set<pair<long long, long long>> s;
  for (long long i = 0; i < (long long)x.size(); i++) {
    s.insert({x[i].second, x[i].first});
  }
  for (long long i = 0; i < n; i++) {
    while (curr < m && x[curr].first < i) {
      s.erase({x[curr].second, x[curr].first});
      curr++;
    }
    if (curr < m) {
      long long tt = (*(s.begin())).first;
      ans -= (n - tt);
    }
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  for (long long i = 0; i < t; i++) {
    SolveTestCase();
  }
  return 0;
}
