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
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define fi first
#define se second
#define pn printf("\n")
#define ssize(x) int(x.size())
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define bitcount(x) __builtin_popcount(x)
#define clz(x) __builtin_clz(x)
#define ctz(x) __builtin_ctz(x)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef double db;
typedef long double ldb;
#define vv vector
/*void read(int &a){
		char c = getchar_unlocked(); a = 0;
		while(c<'0' || '9'<c) c = getchar_unlocked();
		while('0'<=c&&c<='9') a = (a<<3)+(a<<1)+c-'0', c = getchar_unlocked();
}*/
int inf = 2e09; ll infll = 2e18; int mod = (1<<23)*119+1;
int cnt[80000001], cntone[40000001], cnttmp[40000001];
void answer(){
		mt19937 rng(time(0));
		int n; scanf("%d", &n);
		//~ n = 500;
		vv<int> t(n+1, 0);
		for(int i = 1; i <= n; ++i) scanf("%d", &t[i]);
		int add = 20000000, offset = t[1];
		ll result = 0;
		vv<int> a, sum(n+1); a.emplace_back(t[1]); ++cntone[t[1]+add], ++cnt[t[1]+add];
		for(int i = 2; i <= n; ++i){
				sum[i] = t[i], offset += t[i];
				for(int j = i-1; j; --j) sum[j] = sum[j+1]+t[j];
				for(int j = 1; j < i; ++j)
						for(int l = j+1; l <= i; ++l) ++cnt[sum[j]+sum[l]+add-offset], result += cntone[-sum[j]-sum[l]+add];
				
				for(int u : a) ++cnt[u+t[i]+add-offset];
				for(int j = i+1; j <= n; ++j){
						int ss = 0;
						for(int l = j; l; --l) ss += t[l], result += cnt[-ss+add-offset];
				}
				for(int j = 1; j <= i; ++j)
						for(int l = j; l <= i; ++l) ++cnt[sum[j]+sum[l]+add-offset];
				for(int j = i; j; --j) a.emplace_back(sum[j]), ++cntone[sum[j]+add];
				
				for(int j = 1; j <= i; ++j){
						result += cnttmp[-sum[j]+add];
						for(int l = 1; l < j; ++l) ++cnttmp[sum[j]+sum[l]+add];
				}
				for(int j = 1; j <= i; ++j)
						for(int l = 1; l < j; ++l) --cnttmp[sum[j]+sum[l]+add];
		}
		printf("%lld\n", result);
}
signed main(){
		int T = 1;
		//~ scanf("%d", &T);
		//~ ios_base::sync_with_stdio(0); cin.tie(0); //cin >> T;
		for(++T; --T; ) answer();
		return 0;
}