#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<long long> a;
  vector<long long> b;
  a.push_back(0);
  b.push_back(0);
  long long s = 0;
  long long th;
  long long tot = 0;
  for (int i = 0; i < n; i++) {
    cin >> th;
    s += th;
    a.push_back(s);
  }
  for (int i = 1; i <= n; i++) {
    b.push_back(s - a[i]);
  }
  map<long long, long long> aa, bb;
  for (int i = 0; i <= n; i++) {
    if (aa.find(a[i]) == aa.end()) {
      aa.insert(make_pair(a[i], 1ll));
    } else {
      aa[a[i]]++;
    }
    if (bb.find(b[i]) == bb.end()) {
      bb.insert(make_pair(b[i], 1ll));
    } else {
      bb[b[i]]++;
    }
  }
  long long q;
  for (auto i : aa) {
    long long t = s - i.first;
    q = i.second * bb[t];
    tot += q;
  }
  q = n;
  tot = tot - q;
  tot = tot / 2;
  cout << tot;
  return 0;
}
