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
#include <iostream>
#include <vector>
#include <unordered_map>

int n;
std::vector<int> v;

void input() {
    std::cin >> n;
    for (int i = 0; i < n; i++) {
        int x;
        std::cin >> x;
        v.push_back(x);
    }
}

void brute() {
    std::vector<int> v2;
    for (int i = 0; i < n; i++) {
        int x = v[i];
        v2.push_back(x);
//        std::cout << v2.back() << "\n";
        for (int j = i + 1; j < n; j++) {
            x += v[j];
            v2.push_back(x);
//            std::cout << v2.back() << "\n";
        }
    }

    long long result = 0;
    std::unordered_map<int, int> m;
    m[v2[0]] = 1;
    for (int i = 1; i < v2.size(); i++) {
        for (int j = i + 1; j < v2.size(); j++) {
            int r = v2[i] + v2[j];
            if (m.contains(-r)) {
                result += m[-r];
            }
        }

        if (m.contains(v2[i])) {
            m[v2[i]]++;
        } else {
            m[v2[i]] = 1;
        }
    }

    std::cout << result << "\n";
}

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

    input();
    brute();

    return 0;
}