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
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll n,ans;
vector<ll>arr;
map<ll,bool>was;
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for(int i=0;i<n;i++){
        ll a;
        cin >> a;
        was[a]=1;
        arr.push_back(a);

    }
    for(int i=0;i<n;i++){
        ll a = arr[i],sum = a;
        if(i+1 < n){
            arr.push_back(a + arr[i + 1]);
            was[a + arr[i+1]]=1;
            sum+=arr[i + 1];
        }
        for(int j=i+2;j<n;j++){
            ll b = arr[j];
            sum+=b;
            arr.push_back(sum);
            was[sum]=1;

        }
    }
    //for(auto x : arr) cout << x << " ";
    //cout << '\n';
    n = arr.size();
    for(int i=0;i<n;i++){
        ll a = arr[i];
        for(int j=i+1;j<n;j++){
            ll b = arr[j];
            for(int k=j+1;k<n;k++){
                ll c = arr[k];
                if((a + b + c) == 0) ans++;
            }
        }
    }
    cout << ans;
    return 0;
}