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
#include <bits/stdc++.h>
#define fi first
#define sc second
#define pb push_back
#define rep(i,p,k) for(int i=(p);i<(k);++i)
#define forn(i,p,k) for(int i=(p);i<=(k);++i)
#define forr(i,k,p) for(int i=(k)-1;i>=(p);--i)
#define each(a,b) for(auto&a:b)
#define all(v)  begin(v), end(v)
#define RET(smth)   return void(cout<<(smth)<<'\n');
#define sz(v) (int)v.size()
using namespace std;
using pii = pair<int,int>;
using ll = long long;
using Vi = vector<int>;
#ifdef DEBUG
#include "debug.h"
#else
#define debug(...) ;
#endif

int main() {
#ifndef DEBUG
    cin.tie(0) -> sync_with_stdio(0);
#endif
    int n; cin >> n;
    Vi S(n+1);
    forn(i,1,n) cin >> S[i];
    partial_sum(all(S),S.begin());
    const int sh = 3e7;
    vector<int> H(2*sh+1), G(2*sh+1);
    long long res = 0;
    forn(b1,0,n) {
        forn(a1,0,n) forn(a2,0,a1-1) res += H[S[a1]-S[a2]+S[b1]+sh];
        forn(c1,0,n) forn(c2,0,c1-1) H[S[c2]-S[c1]+S[b1]+sh]++;
    }
    forn(a1,0,n) forn(a2,0,a1-1) G[2*S[a1]-2*S[a2] + sh]++;
    forn(b1,0,n) forn(b2,0,b1-1) res -= 3*G[S[b2]-S[b1]+sh];
    forn(i,0,n) forn(j,i+1,n) if(S[i] == S[j]) res += 2;
    cout << res / 6 << '\n';
    return 0;
}