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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0,_##i##__end=int(n);i<_##i##__end;++i)
#define per(i,n) for(int i=int(n)-1;i>=0;--i)
#define rep1(i,n) for(int i=1,_##i##__end=int(n);i<=_##i##__end;++i)
#define per1(i,n) for(int i=int(n);i>=1;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldb;
using namespace std;
const ll mod1=998244353;
const ll mod2=1000000007;
unsigned time_related_rand()
{
	return unsigned(std::chrono::steady_clock::now().time_since_epoch().count());
}
int n;
int x[505];
int s[191981],cnt;
const int V=20000005;
int c[V<<1]; 
ll answer;
int main()
{
	ios_base::sync_with_stdio(false);
	cin>>n;
	rep1(i,n)
	{
		cin>>x[i];x[i]+=x[i-1];
	}
	rep1(i,n) rep(j,i) s[++cnt]=x[i]-x[j];
	rep(i,n+1)
	{
		rep1(j,cnt)
		{
			answer+=c[s[j]+x[i]+V];
		}
		rep1(j,cnt)
		{
			++c[x[i]-s[j]+V];
		}
	}
	memset(c,0,sizeof(c));
	rep1(i,cnt) ++c[s[i]+V];
	rep1(i,cnt) answer-=3*c[V-2*s[i]];
	rep1(i,cnt) if(s[i]==0) answer+=2;
//	cout<<answer<<endl;
	cout<<answer/6<<endl;
	return 0;
}
/* things to check
1.  int overflow or long long memory need
2.  recursion/array/binary search/dp/loop bounds
3.  precision
4.  special cases(n=1,bounds)
5.  delete debug statements
6.  initialize(especially multi-tests)
7.  = or == , n or m ,++ or -- , i or j , > or >= , < or <=
8.  keep it simple and stupid
9.  do not delete, use // instead
10. operator priority
11. is there anything extra to output?
12. ...
*/

/* something to think about
1. greedy? dp? searching? dp with matrix/ segment tree? binary search?
2. If contains "not", why not ?????? or few affect?
*/