#include <bits/stdc++.h>
using namespace std;
long long func(long long x) {
  long long tmp1 = 1, tmp2 = 1;
  for (long long i = 1; i <= x - 2; i++) {
    tmp1 *= i;
    tmp2 *= i;
  }
  tmp1 *= (x - 1) * x;
  return tmp1 / (2 * tmp2);
}
int main() {
  int n;
  cin >> n;
  vector<long long> a(n + 1, 0);
  map<long long, long long> list;
  list[0] = 1;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    a[i] = x + a[i - 1];
    list[a[i]]++;
  }
  long long ans = 0;
  for (auto i = list.begin(); i != list.end(); i++) {
    long long tmp = i->second;
    if (tmp > 1) {
      ans += func(tmp);
    }
  }
  cout << ans << endl;
  return 0;
}
