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

using namespace std;
vector<int> v;
vector<int> b;

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int n;
    cin >> n;
    v = vector<int>(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }

    for (int i = 0; i < n; i++) {
        int w = 0;
        for (int j = i; j < n; ++j) {
            w += v[j];
            b.push_back(w);
        }
    }

    sort(b.begin(), b.end());
    int siz = b.size();
    int wyn = 0;
    for (int i = 0; i < siz; ++i) {
        unordered_map<int,int> s;
        int left = b[i];
        for (int j = i+1; j < siz; ++j) {
            int cur = left + b[j];
            if(s.count(b[j]) > 0) {
                wyn += s[b[j]];
            }
            if(s.count(-cur) > 0) s[-cur]++;
            else s[-cur] = 1;
        }
    }

    cout<<wyn<<"\n";
}

/*
 10
0 0 0 0 0 0 0 0 0 0

 3
 7 -4 -2

 */