#include <bits/stdc++.h>
using namespace std;
vector<vector<long long int>> cn(long long int n, long long int m) {
  return vector<vector<long long int>>(n, vector<long long int>(m));
}
bool compare(char &s1, char &s2) { return s1 > s2; }
bool sortmahstyle(const pair<long long int, long long int> &a,
                  const pair<long long int, long long int> &b) {
  if (a.first < b.first) return true;
  if (a.first == b.first && a.second != b.second) return true;
  return false;
}
long long int const mod = 998244353;
long long int const inf = 1e6 + 1;
long long int const maxn = 5e5 + 1;
vector<long long int> adj[maxn];
vector<pair<long long int, long long int>> ds;
long long int vis1[maxn], vis2[maxn];
long long int dfs1(long long int x) {
  vis1[x] = 1;
  long long int cnt = 1;
  for (long long int ch : adj[x])
    if (vis1[ch] == 0) cnt += dfs1(ch);
  return cnt;
}
long long int dfs2(long long int x) {
  vis2[x] = 1;
  long long int cnt = 1;
  for (long long int ch : adj[x])
    if (vis2[ch] == 0) cnt += dfs2(ch);
}
void solve() {
  long long int n;
  cin >> n;
  long long int a[n];
  for (long long int i = 0; i < n; i++) cin >> a[i];
  map<long long int, pair<long long int, long long int>> cnt;
  long long int kk = 0;
  for (long long int i = 0; i < n; i++) {
    kk += a[i];
    cnt[kk] = {0, -1};
  }
  cnt[0].first = 1;
  cnt[0].second = -1;
  long long int sum = 0, ans = 0;
  long long int L = -1, R = -1;
  for (long long int i = 0; i < n; i++) {
    sum += a[i];
    long long int curL =
        max(L, cnt[sum].second + 1 + (cnt[sum].first > 0 ? 1 : 0));
    long long int prevR = R;
    long long int red = max(0ll, prevR - curL + 1);
    long long int tot = i - curL + 1;
    ans += tot * (tot + 1) / 2 - red * (red + 1) / 2;
    R = i;
    L = max(L, curL);
    cnt[sum] = {cnt[sum].first + 1, i};
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  t = 1;
  for (long long int testcases = 0; testcases < t; testcases++) {
    solve();
  }
  return 0;
}
