#include <bits/stdc++.h>
using namespace std;
long long int ans;
vector<long long int> A;
vector<long long int> bun(int l, int r, bool isL) {
  vector<long long int> ret;
  if (r - l == 1) {
    if (A[l] == 0) ans++;
    ret.push_back(A[l]);
    return ret;
  }
  vector<long long int> left = bun(l, (l + r) / 2, true);
  vector<long long int> right = bun((l + r) / 2, r, false);
  long long int li = 0, ri = 0, lc = 0, rc = 0;
  while (li < left.size() && ri < right.size()) {
    int memo;
    if (left[li] + right[ri] == 0) {
      memo = left[li];
      while (li < left.size() && left[li] == memo) {
        li++;
        lc++;
      }
      while (ri < right.size() && right[ri] == memo * -1) {
        ri++;
        rc++;
      }
      ans += lc * rc;
      lc = 0;
      rc = 0;
      continue;
    }
    if (left[li] + right[ri] > 0) {
      ri++;
    } else {
      li++;
    }
  }
  long long int rui = 0;
  if (isL) {
    while (l != r) {
      rui += A[r - 1];
      ret.push_back(rui);
      r--;
    }
  } else {
    while (l != r) {
      rui += A[l];
      ret.push_back(rui);
      l++;
    }
  }
  sort(ret.begin(), ret.end());
  if (!isL) {
    reverse(ret.begin(), ret.end());
  }
  return ret;
};
int main(void) {
  int n;
  long long int a;
  cin >> n;
  ans = 0;
  for (int i = 0; i < (int)(n); i++) {
    cin >> a;
    A.push_back(a);
  }
  bun(0, n, true);
  cout << ans << endl;
  return 0;
}
