#include<bits/stdc++.h>

#define INF 1e9
#define llINF 1e18
#define MOD 1e9+7
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
using namespace std;
map<ll,ll>ma;
int main(){
  int a;
  cin>>a;
  vector<ll>num(a);
  vector<ll>sum(a);
  for(int i=0;i<a;i++){
    cin>>num[i];
    if(i!=0)
      sum[i]=sum[i-1]+num[i];
    else
      sum[i]=num[i];
  }
  sort(sum.begin(),sum.end());
  ll ans=0;
  for(int i=0;i<a-1;i++){
    int cnt=1;
    while(sum[i]==sum[i+1]&&i<a-2){
      cnt++;
      i++;
    }
    if(i==a-2&&sum[i]==sum[i+1])cnt++;
    if(sum[i]==0)
      abs+=cnt*(cnt+1)/2;
    else
      ans+=cnt*(cnt-1)/2;
  }
  cout<<ans<<endl;
  return 0;
}
