#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 2e5 + 100;
long long n, pref[MAXN], suff[MAXN], a[MAXN], ct[MAXN];
vector<pair<int, long long> > pos;
vector<pair<int, int> > g;
bool u[MAXN];
void bin_search_pref(int l, int r, long long val) {
  int orig = l;
  if (l > r) {
    return;
  }
  while (l < r) {
    int mid = (l + r) >> 1;
    if (pref[mid] - pref[orig - 1] == val) {
      r = mid;
      break;
    } else if (pref[mid] - pref[orig - 1] > val) {
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  u[orig - 1] = 1;
  g.push_back(make_pair(orig - 1, r));
}
void bin_search_suff(int l, int r, long long val) {
  int orig = r;
  if (l > r) {
    return;
  }
  while (l < r) {
    int mid = (l + r) >> 1;
    if (suff[mid] - suff[orig + 1] == val) {
      l = mid;
      break;
    } else if (suff[mid] - suff[orig + 1] > val) {
      l = mid + 1;
    } else {
      r = mid - 1;
    }
  }
  u[l] = 1;
  g.push_back(make_pair(l, orig + 1));
}
int main() {
  cin >> n;
  long long ai;
  for (int i = 1; i <= n; ++i) {
    cin >> ai;
    if (ai < 0) {
      pos.push_back(make_pair(i, ai));
    } else if (!ai) {
      g.push_back(make_pair(i, i));
    } else {
      pref[i] = pref[i - 1] + ai;
    }
  }
  for (int i = n; i >= 1; --i) {
    suff[i] = suff[i + 1] + pref[i] - pref[i - 1];
  }
  for (int i = 0; i < pos.size(); ++i) {
    int l = pos[i].first;
    int r = pos[i + 1].first;
    long long val = pos[i].second;
    if (i == pos.size() - 1) {
      r = n + 1;
    }
    bin_search_pref(l + 1, r - 1, val * -1);
    r = l;
    l = pos[i - 1].first;
    if (!i) {
      l = 0;
    }
    bin_search_suff(l + 1, r - 1, val * -1);
  }
  long long ans = 0;
  sort(g.begin(), g.end());
  ans += g.size();
  for (int i = 0; i < g.size(); ++i) {
    int l = g[i].first;
    int r = g[i].second;
    ct[r + 1] += ct[l] + 1;
  }
  for (int i = 0; i < g.size(); ++i) {
    int l = g[i].first;
    int r = g[i].second;
    ans += ct[l];
  }
  cout << ans;
  return 0;
}
