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
//泥の分際で私だけの大切を奪おうだなん
#include<bits/stdc++.h>
using namespace std;
#define ll long long
inline int read(){
   int s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
const int B=3.01e7;
int f[61000003],a[503];
signed main()
{
	int n=read();
	for(int i=1; i<=n; ++i) a[i]=a[i-1]+read();
	ll ans=0;
	for(int i=0; i<=n; ++i)
	{
		for(int j=0; j<=n; ++j)
			for(int k=j+1; k<=n; ++k)
				ans+=f[B-(a[i]+a[k]-a[j])];
		for(int j=0; j<=n; ++j)
			for(int k=j+1; k<=n; ++k)
				++f[B-a[i]+a[k]-a[j]];
	}
	map<int,int> mp;
	for(int i=0; i<=n; ++i)
		for(int j=i+1; j<=n; ++j)
			++mp[a[j]-a[i]];
	for(auto [x,y]:mp)	
		if(x!=0&&abs(x)%2==0&&mp.count(-x/2))
			ans-=3ll*y*mp[-x/2];
	//a+b+b=0: a=2b
	int o=mp[0];
	ans-=o,ans-=3ll*o*(o-1);
	//a+a+a=0: a=3b
	printf("%lld\n",ans/6);
	return 0;
}