#include <bits/stdc++.h>
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
long long fac[5100000], finv[5100000], inv[5100000];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < 5100000; i++) {
    fac[i] = fac[i - 1] * i % 1000000007;
    inv[i] = 1000000007 - inv[1000000007 % i] * (1000000007 / i) % 1000000007;
    finv[i] = finv[i - 1] * inv[i] % 1000000007;
  }
}
long long int nCr(long long int n, long long int r) {
  if (n < r) return 0;
  if (n < 0 || r < 0) return 0;
  return fac[n] * (finv[r] * finv[n - r] % 1000000007) % 1000000007;
}
int main() {
  long long int A, B, C, D, E, L, R, X, Y, W, H, N, M, K, sum = 0, num = 0,
                                                          flag = 0;
  string S, T;
  cin >> N;
  vector<long long int> P(N, 0);
  for (long long int i = 0; i < N; i++) cin >> P[i];
  for (long long int i = 1; i < N; i++) P[i] += P[i - 1];
  P.push_back(0);
  sort(P.begin(), P.end());
  map<long long int, long long int> Q;
  for (long long int i = 1; i < N + 1; i++)
    if (P[i] == P[i - 1]) Q[P[i]]++;
  COMinit();
  for (pair<long long int, long long int> v : Q) sum += nCr(v.second + 1, 2);
  cout << sum << endl;
}
