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

struct tr {
	int a, b, c;
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	vector <int> v(n+1);
	for (int i = 0; i < n; i++) {
		cin >> v[i+1];
	}
	vector <int> pref(n+1);
	for (int i = 1; i <= n; i++) {
		pref[i] = pref[i-1] + v[i];
	}
	ll res = 0;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			for (int k = 0; k <= n; k++) {
				for (int ii = i+1; ii <= n; ii++) {
					for (int jj = j+1; jj <= n; jj++) {
						for (int kk = k+1; kk <= n; kk++) {
			if (pref[i] + pref[j] + pref[k] !=
				pref[ii] + pref[jj] + pref[kk])
				continue;
			set <pair <int, int> > s;
			s.insert({i, ii});
			s.insert({j, jj});
			s.insert({k, kk});
			if (s.size() != 3)
				continue;
	//		cout << pref[m[i].a] << " " << pref[m[i].b] << " " << pref[m[i].c] << "\n";
	//		cout << pref[m[j].a] << " " << pref[m[j].b] << " " << pref[m[j].c] << "\n\n";
			res++;
							
						}
					}
				}
			}
		}
	}
	cout << res/6 << "\n";
}