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
#include <bits/stdc++.h>
using namespace std;
long long pref[507];
long long s1,s2,s3,res;
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n,a;
	pair<int,int>p1,p2,p3;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a;
		pref[i]=pref[i-1]+a;
	}
	for(int a=1;a<=n;a++){
		for(int b=a;b<=n;b++){
			for(int c=b;c<=n;c++){
				for(int x=0;a+x<=n;x++){
					for(int y=0;b+y<=n;y++){
						for(int z=0;c+z<=n;z++){
							if(a==b and y>=x) continue;
							if(b==c and z>=y) continue;
							if(a==c and z>=x) continue;
								s1=pref[a+x]-pref[a-1];
								s2=pref[b+y]-pref[b-1];
								s3=pref[c+z]-pref[c-1];
								if(s1+s2+s3==0){
									res++;
									//cout<<a<<' '<<x<<' '<<b<<' '<<y<<' '<<c<<' '<<z<<'\n';	
								} 
						}
					}
				}
			}
		}
	}
	cout<<res<<'\n';
	return 0;
}