#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  long long ans = 0;
  for (int i = 0; i < N; i++) {
    if (A[i] == 0) {
      ans--;
    }
  }
  for (int i = 1; i < N; i++) {
    A[i] += A[i - 1];
  }
  sort(A.begin(), A.end());
  for (int i = 0; i < N;) {
    int j = i;
    int cnt = 0;
    while (A[j] == A[i]) {
      cnt++;
      j++;
    }
    if (A[i] == 0) {
      ans += (cnt + 1) * cnt / 2;
    } else {
      ans += (cnt - 1) * cnt / 2;
    }
    i = j;
  }
  cout << ans << endl;
}
