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
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <tuple>


using namespace std;

#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define x first
#define y second

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;

int n;
vll a;
vll buc;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    cin>>n;

    a.pb(0);
    ll ans=0;

    for(int i=0; i<n; i++){
        ll ai;
        cin >> ai;
        a.pb(a.back()+ai);
    }
    for(int i=0; i<n; i++){
        for(int j=1; j<=n-i; j++){
            buc.pb(a[i+j]-a[i]);
        }
    }

    unordered_map<ll, int> cache;
    for(int i=0; i<buc.size(); i++){
        for(int j=i+1; j<buc.size(); j++){
            cache[buc[j]]++;
        }
        for(int j=i+1; j<buc.size(); j++){
           ll p = buc[i] + buc[j];
           cache[buc[j]]--;
           ans += cache[-p];
        }
    }

    cout << ans << "\n";

    return 0;
}