#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int ans,sum,a[300000],b[300000],n;
map<int,int>m;
signed main(){
	cin>>n;
	rep(i,n)cin>>a[i],b[i]=a[i];
	rep(i,n-1)b[i+1]+=b[i];
	rep(i,n)m[b[i]]++;
	rep(i,n){
		ans+=m[sum];
		m[b[i]]--;
		sum+=a[i];
	}
	cout<<ans<<endl;
}