#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
 
using namespace std;
 
int n,a[200010],q=1,g;
long long int xx,sm=0,b[200010];
vector<int> s;

vector<int> akrk(int target[],int size){ 
    vector<int> result;
    int repeats=1,number=target[0];
    for(int i=1;i<size;i++){
        if(number==target[i])repeats++;
        else{
            number=target[i];
            result.push_back(repeats);
            repeats=1;
        }
    }
    result.push_back(repeats);
    return result;
}

int main(){
    scanf("%d",&n);
    b[0]=0;
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        b[i+1]=b[i]+a[i];
    }
    sort(b,b+n+1);
    g=b[0];
    s=akrk(b,n+1);
    
    for(int itr:s){
        printf("%d\n",itr);
        sm+=itr*(itr-1)/2;
    }
    printf("%lld\n",sm);
}