#include <iostream>
#include <vector>
#include <map>
#include <cmath>

using namespace std;
using ll = long long int;
int main(){
  ll n;
  vector<pair<ll,ll>> ANS(1e6, {0,0});
  vector<ll> SUM(n, 0LL);
  
  for(ll i=0;i<n;i++){
    ll vi;
    cin >> vi;
    if(i!=0)
      SUM[i] = SUM[i-1];
    SUM[i] += vi;
  }
  
  for(auto e: SUM){
    if(e>0){
      ANS[e] = {ANS[e].first+1, ANS[e].second};
    }else{
       ANS[e] = {ANS[e].first, ANS[e].second+1};
    }
  }
  
  ll ans=0;
  for(auto e:ANS){
    if(e=0)
      ans+=e.second;
    else
      ans += (e.first * e.second);
  }
  
}