#include <bits/stdc++.h>
using namespace std;
long long mod(long long a, long long b) { return (a % b + b) % b; }
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void Judge(bool b) { b ? Yes() : No(); }
void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void JUDGE(bool b) { b ? YES() : NO(); }
long long powMod(long long a, long long b, long long c) {
  long long ans = 1;
  for (int i = 0; i < (b); ++i) {
    ans = ans * a % c;
  }
  return ans;
}
double distance(long long x1, long long y1, long long x2, long long y2) {
  return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
template <typename T>
void ppp(T n) {
  cout << n << endl;
}
template <typename T>
void dpp(T n) {
  cerr << n << endl;
}
template <typename T>
void vpp(T a) {
  for (int i = 0; i < (a.size()); ++i) {
    cout << a[i] << endl;
  }
}
template <typename T>
void vdp(T a) {
  for (int i = 0; i < (a.size()); ++i) {
    cerr << a[i];
  }
  cerr << endl;
}
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int ddy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
long long fact(long long n) {
  if (n == 0LL) return 0LL;
  long long ans = 1;
  for (int i = 1; i <= n; ++i) {
    ans *= i;
  }
  return ans;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long ans = 0;
  int n;
  cin >> n;
  long long a[n];
  for (int i = 0; i < (n); ++i) {
    cin >> a[i];
  }
  long long sum[n + 1];
  sum[0] = 0;
  for (int i = 0; i < (n); ++i) {
    sum[i + 1] = sum[i] + a[i];
  }
  map<long long, long long> mp;
  for (auto x : sum) {
    mp[x]++;
  }
  for (auto m : mp) {
    ans += fact(m.second - 1LL);
  }
  ppp(ans);
  return 0;
}
