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
#include <bits/stdc++.h>
using namespace std;

int n;
int a[500];
vector<int> seq;

int cnt[20000000];

long long res;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n;
    seq.reserve(n*(n+1)/2);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }

    for(int beg = 0; beg < n; beg++){
        int sum = 0;
        for(int end = beg; end < n; end++){
            sum += a[end];
            seq.push_back(sum);
        }
    }

    auto cnt2 = cnt + 10000000;

    for(int a = 0; a < seq.size(); a++){
        for(int b = a+1; b < seq.size(); b++){
            int sum = seq[a] + seq[b];
            sum = -sum;
            if(sum >= -10000000 && sum <= 10000000){
                res += cnt2[sum];
            }
        }
        cnt2[seq[a]]++;
    }

    cout << res << "\n";
}