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
58
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;


const ll baza = 30000050;
ll ilepar[2*baza+10];

signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll i;
	ll n;
	cin>>n;
	ll tab[n+1];
	ll pre[n+1];
	pre[0] = 0;
	for (i = 1; i <= n; i++){
		cin>>tab[i];
		pre[i] = pre[i-1]+tab[i];
	}
	ll wy = 0;
	for (ll a2 = 0; a2 <= n; a2++){
		for (ll b1 = 0; b1 <= n; b1++){
			for (ll a1 = b1+1; a1 <= n; a1++){
				ll nasz = pre[a1]-pre[b1]+pre[a2];
				//cout<<"Przedziały "<<b1+1<<" "<<a1<<" # ? "<<a2<<" # ? ? : "<<ilepar[baza+nasz]<<"\n";
				wy += ilepar[baza+nasz];
			}
		}
		for (ll b3 = 0; b3 <= n; b3++){
			for (ll a3 = b3+1; a3 <= n; a3++){
				ll nasz = pre[a2]+pre[b3]-pre[a3];
				//cout<<"Dodajemy "<<a2+1<<" "<<b3+1<<" "<<a3<<" ### "<<nasz<<"\n";
				ilepar[baza+nasz]++;
			}
		}
	}
	for (i = 0; i < 2*baza; i++) ilepar[i] = 0;
	
	for (i = 0; i <= n; i++){
		for (ll j = i+1; j <= n; j++){
			ilepar[baza+pre[j]-pre[i]]++;
		}
	}
	//cout<<wy<<"\n";
//cout<<ilepar[baza]<<"\n";
	wy -= 6*ilepar[baza]*(ilepar[baza]-1)/2+ilepar[baza];
	for (i = 0; i < 2*baza; i++){
		if (i == baza) continue;
		ll drugi = baza+(i-baza)*(-2);
		if (drugi > 0 && drugi < 2*baza){
			wy -= 3*ilepar[drugi]*ilepar[i];
		}
	}
	cout<<wy/6<<"\n";
	
}