#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;

int main() {
int n;
  cin>>n;
  ll k[n];
  rep(i, n)cin>>k[i];
    ll sumsum[n+1];
  rep(i, n){if(!i) sumsum[i]=k[0];
    else sumsum[i]=sumsum[i-1]+k[i];}
  sumsum[n]=0;
  
  sort(sumsum,sumsum+n+1);

  ll renzoku=0;
  ll renx[n]={0};
  bool counting=false;
  for(int i=1;i<=n;i++){
    if(counting){if(sumsum[i]==sumsum[i-1])
    {renzoku++;
                 if(i==n) renx[n]=renzoku;
    continue;}

                 else {renx[i-1]=renzoku;
                 renzoku=0;
  counting=false;}
                }
      
      
      if(sumsum[i]==sumsum[i-1]){
        counting=true;
        renzoku=2;
        if(i==n) renx[n]=2;
      }
  }
  
  ll ans=0;
  rep(i, n+1){ans+=renx[i]*(renx[i]-1)/2;}
  
  cout<<ans<<endl;


}
