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
#include <algorithm>
#include <cstdio>
#include <map>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define VAR(v,w) __typeof(w) v=(w)
#define FORE(it,c) for(VAR(it,(c).begin());it!=(c).end();++it)
#define FT first
#define SD second
#define INT(x) int x; scanf("%d", &x)

typedef long long LL;

int a[500], s[501];

int main() {
	INT(n);
	REP(i,n) scanf("%d", &a[i]);
	s[0] = 0;
	REP(i,n) s[i + 1] = s[i] + a[i];
	map<int, int> m;
	REP(i,n) FOR(j,i+1,n+1) ++m[s[j] - s[i]];
	LL r = 0;
	FORE(it,m) FORE(jt,m) {
		int x = -it->FT - jt->FT;
		VAR(kt, m.find(x));
		if (kt == m.end()) continue;
		LL a = it->SD;
		LL b = max(jt->SD - (it->FT == jt->FT), 0);
		LL c = max(kt->SD - (it->FT == kt->FT) - (jt->FT == kt->FT), 0);
		r += a * b * c;
	}
	r /= 6;
	printf("%lld\n", r);
}