#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  long long A[N], B[N + 1];
  B[0] = 0LL;
  int numZero = 0;
  bool ignoreZeroCount = false;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (A[i] == 0) {
      numZero++;
    }
    B[i + 1] = B[i] + A[i];
    if (B[i + 1] == 0 && A[i] != 0) {
      ignoreZeroCount = true;
    }
  }
  unsigned long long ans = 0ULL;
  sort(B, B + (N + 1));
  for (int i = 0; i < N + 1; i++) {
    for (int j = i + 1; j <= N + 1; j++) {
      if (j == N + 1 || B[j] != B[i]) {
        if (j == N + 1) {
          unsigned long long diff = j - i + 1ULL;
          if (diff > 1) {
            diff -= 1ULL;
            ans += (unsigned long long)((diff * (diff + 1ULL)) / 2ULL);
          }
          i = j;
          break;
        } else {
          unsigned long long diff = j - i;
          if (diff > 1) {
            diff -= 1ULL;
            ans += (unsigned long long)((diff * (diff + 1ULL)) / 2ULL);
          }
          i = j;
          break;
        }
      }
    }
  }
  if (!ignoreZeroCount && numZero > 0) {
    ans -= numZero + 1;
  }
  cout << ans << endl;
  return 0;
}
