#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  vector<long long> s(N + 1);
  s[0] = 0;
  for (int i = 0; i < N; i++) s[i + 1] = s[i] + a[i];
  map<long long,int> M;
  set<long long> S;
  for (int i = 0; i <= N; i++){
    if (!M.count(s[i])){
      M[s[i]] = 1;
      S.insert(s[i]);
    } else {
      M[s[i]]++;
    }
  }
  long long ans = 0;
  for (auto i : S){
    ans += M[i] * (M[i] - 1) / 2;
  }
  cout << ans;
}