1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include<bits/stdc++.h>
#define LL long long
#define LLL __int128
#define uint unsigned
#define ldb long double
#define uLL unsigned long
using namespace std;
const int N=505,M=6e7+5;
int n,m,a[N],s[M];LL ans;
vector<int>f[N],g[N];
signed main(){
    cin.tie(0)->sync_with_stdio(0);
    cin>>n;
    for(int i=1;i<=n;++i)cin>>a[i],a[i]+=a[i-1];
    for(int x=0;x<=n;++x)
        for(int y=x+1;y<=n;++y)
            for(int z=0;z<=n;++z)
                f[z].emplace_back(a[y]-a[x]-a[z]),
                g[z].emplace_back(a[x]-a[y]-a[z]);
    for(int i=0;i<=n;++i){
        for(auto v:g[i])ans+=s[v+30000000];
        for(auto v:f[i])++s[v+30000000];
    }
    memset(s,0,sizeof(s));
    for(int x=0;x<=n;++x)
        for(int y=x+1;y<=n;++y)
            ++s[a[y]-a[x]+20000000];
    for(int i=-10000000;i<=10000000;++i)
        if(i)ans-=3*s[i+20000000]*s[20000000-i-i];
    ans-=1ll*s[20000000]*s[20000000]*s[20000000],ans+=s[20000000]*(s[20000000]-1ll)*(s[20000000]-2ll);
    return cout<<ans/6,0;
}
/*
*/