#include <bits/stdc++.h>
using namespace std;
int N;
int A[300000] = {0};
long long int tA[300000] = {0};
long long int nCr(long long int n, int r) { return n * (n - 1) / 2; }
int main() {
  cin >> N;
  priority_queue<long long int> pque;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  tA[0] = A[0];
  for (int i = 1; i < N; i++) {
    tA[i] = tA[i - 1] + A[i];
  }
  sort(tA, tA + N);
  int count = 0;
  int ind = 1;
  long long int nowN = tA[0];
  for (int i = 1; i < N; i++) {
    if (nowN == 0) {
      if (tA[i] == 0)
        ind++;
      else {
        if (ind > 0) count += nCr(ind + 1, 2);
        ind = 1;
        nowN = tA[i];
      }
    } else {
      if (tA[i] == nowN)
        ind++;
      else {
        if (ind > 1) count += nCr(ind, 2);
        ind = 1;
        nowN = tA[i];
      }
    }
  }
  if (nowN == 0) {
    if (ind > 0) count += nCr(ind + 1, 2);
  } else {
    if (ind > 1) count += nCr(ind, 2);
  }
  cout << count << endl;
}
