#include <bits/stdc++.h>
using namespace std;
int N;
vector<long long> A;
vector<long long> A_t;
vector<int> num;
long long res;
long long maxA = 0;
long long minA = 0;
long long myabs(long long a) {
  if (a < 0) {
    return -a;
  } else {
    return a;
  }
}
long long mymax(long long a, long long b) {
  if (a > b) {
    return a;
  } else {
    return b;
  }
}
long long mymin(long long a, long long b) {
  if (a > b) {
    return b;
  } else {
    return a;
  }
}
int main() {
  cin >> N;
  A = vector<long long>(N);
  A_t = vector<long long>(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (i == 0) {
      A_t[i] = A[i];
    } else {
      A_t[i] += A_t[i - 1] + A[i];
      maxA = mymax(maxA, A_t[i]);
      minA = mymin(minA, A_t[i]);
    }
  }
  long long temp_min = myabs(minA);
  num = vector<int>(temp_min + maxA + 1, 0);
  num[temp_min + 0]++;
  for (int i = 0; i < N; i++) {
    num[temp_min + A_t[i]]++;
  }
  for (int i = 0; i <= maxA; i++) {
    long long n = num[i];
    if (n != 0) {
      res += (n * (n - 1)) / 2;
    }
  }
  cout << res << endl;
  return 0;
}
