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