#include <iostream>
#include <algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(){
	int n; cin>>n;
	long a[n+1]={};
	rep(i,n){
		int x; cin>>x;
		a[i+1]=a[i]+x;
	}
	sort(a,a+n+1);
	rep(i,n+1) cout<<a[i]<<endl;
	int cnt=0,sum=0;
	rep(i,n+1){
		if(a[i+1]==a[i]) cnt++;
		else{
			while(cnt>0){
				sum+=cnt; cnt--;
			}
		}
	}
	cout<<sum<<endl;
	return 0;
}
