#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int a[334334],cnt[334334];int n,memo=0,ans=0,cnta=0;
signed main(){
	cin>>n;
	rep(i,n)cin>>a[i];
	rep(i,n){
		memo+=a[i];
		cnt[i]=memo;
	}
	sort(cnt,cnt+n);
	rep(i,n){
		if(cnt[i]==0)cnta++;
	}
	rep(i,n){
		if(cnt[i]==cnt[i+1])continue;
		ans+=((s64)(upper_bound(cnt,cnt+n,cnt[i])-lower_bound(cnt,cnt+n,cnt[i])))*(upper_bound(cnt,cnt+n,cnt[i])-lower_bound(cnt,cnt+n,cnt[i])-1)/2;
	}
	cout<<ans+cnta<<endl;
}