#include <bits/stdc++.h>
using namespace std;
void comb(vector<vector<long long int> > &v) {
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int k = 1; k < v.size(); k++) {
    for (int j = 1; j < k; j++) {
      v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
    }
  }
}
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  vector<vector<long long int> > v(N + 1, vector<long long int>(N + 1, 0));
  comb(v);
  map<int, int> x;
  for (auto i = 0; i < N; ++i) {
    cin >> A[i];
  }
  int count = 0;
  int sum = 0;
  for (auto j = 0; j < N; ++j) {
    sum += A[j];
    x[sum] += 1;
  }
  for (auto iter = x.begin(); iter != x.end(); ++iter) {
    int l = iter->first;
    int r = iter->second;
    if (l == 0) {
      count += v[r + 1][2];
    } else if (r > 1) {
      count += v[r][2];
    }
  }
  cout << count << endl;
}
