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

const int U = 1<<25;
int q[U+U];

void wstaw(int s) {
	if (s >= U || s < -U) return;
	q[s+U]++;
}

int pyt(int s) {
	return q[s+U];
}

int main() {
	int n;
	scanf("%d", &n);
	vector<int> a(n), s(n+1);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		s[i+1] = s[i] + a[i]; 
	}
	long long ret = 0;
	for (int i = 0; i <= n; i++) {
		if (i) {
			for (int z = i+1; z <= n; z++) for (int y = z; y <= n; y++) ret += pyt(s[y]+s[z]-s[i]);
			for (int y = i+1; y <= n; y++) for (int z = y+1; z <= n; z++) ret += pyt(s[y]+s[z]-s[i-1]);
			for (int c = i-1; c < n; c++) for (int z = 1+max(i, c); z <= n; z++) ret += pyt(s[i]+s[z]-s[c]);
		}
		for (int a = 0; a < i; a++) for (int x = a+1; x <= n; x++) wstaw(s[a]+s[i]-s[x]);
	}
//	printf("%lld\n", ret);
	for (int i = 0; i < U+U; i++) q[i] = 0; 
	for (int i = 0; i <= n; i++) {
		for (int y = i+1; y <= n; y++) ret += pyt(s[i]+s[y]);
		for (int x = 0; x < i; x++) wstaw(3*s[x]-s[i]);
		for (int c = i+1; c <= n; c++) for (int z = c+1; z <= n; z++) wstaw(2*s[i]+s[c]-s[z]);
	}
  printf("%lld\n", ret);
	return 0;
}