#include<iostream>
#include<string>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>

using namespace std;

int main(){
	//ios::sync_with_stdio(false);
	//cin.tie(0);

	int n;
	cin >> n;

	int a[n];
	for(int i=0;i<n;i++){
		cin >> a[i];
	}

	long long rui[n+1] = {};
	for(int i=1;i<n+1;i++){
		rui[i] = rui[i-1] + a[i-1];
	}

	long long ans=0;
	for(int i=0;i<n+1;){
		auto up = upper_bound(rui+i,rui+n+1,rui[i]);
		for(int j=up-(rui+i)-1;j>0;j--){
			ans += j;
		}
		i = up-rui;
	}

	cout << ans << "\n";
	return 0;
}
