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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
#include <vector>
#define nl '\n'

using namespace std;
using ll = long long;

ll counts[20000002];

int n;

ll prefix[501];

vector<ll> vals;

ll res = 0;

int main()
{
	cin.tie(0)->sync_with_stdio(0);
	cin>>n;
	for(int i=1; i<=n; i++){
		cin>>prefix[i];
	}
	for(int i=1; i<=n; i++){
		prefix[i] += prefix[i-1];
	}
	for(int i=1; i<=n; i++){
		for(int j=1; j<=i; j++){
			counts[prefix[i]-prefix[j-1]+10000000]++;
		}
	}
	vals.reserve(125001);
	for(int i=0; i<20000002; i++){
		if(counts[i]){
			vals.push_back(i-10000000);
		}
	}
	for(int i=0; i<vals.size(); i++){
		for(int j=0; j<vals.size(); j++){
			if(i==j) continue;
			ll sum = vals[i] + vals[j];
			//cerr<<vals[i]<<' '<<vals[j]<<' '<<-sum<<nl;
			if(-sum == vals[i] || -sum == vals[j]) continue;
			ll comb = counts[vals[i] + 10000000] * counts[vals[j] + 10000000] * counts[10000000-sum];
			//cerr<<comb<<nl;
			res += comb;
		}
		int eff_add = vals[i] + 10000000;
		//cerr<<vals[i]<<' '<<counts[eff_add]<<'\n';
		if(vals[i] == 0) continue;
		res += counts[eff_add] * (counts[eff_add]-1) * counts[10000000-2*vals[i]] * 3;
	}
	res += counts[10000000] * (counts[10000000] - 1) * (counts[10000000] - 2);
	cout<<res/6<<'\n';
	return 0;
}