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 <ranges>
#include <vector>
#include <iostream>
#include <numeric>
#include <algorithm>
#include <unordered_map>
#include <set>
#include <stack>

using namespace std;

typedef long long ll;

int main() {
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;

    vector<int> seq;
    int a;
    for (int i = 0; i < n; i++) {
        cin >> a;
        seq.push_back(a);
    }

    vector<ll> fav_seq;
    
    for (int i = 0; i < n; i++) {
        for (int j = i; j < n; j++) {
            int sum = 0;
            for (int k = i; k <= j; k++) {
                sum += seq[k];
            }
            fav_seq.push_back(sum);
        }
    }

    ll sum = 0;

    unsigned long size = fav_seq.size();
    for (int i = 0; i < size; i++) {
        for (int j = i+1; j < size; j++) {
            for (int k = j+1; k < size; k++) {
                auto c1 = fav_seq[i];
                auto c2 = fav_seq[j];
                auto c3 = fav_seq[k];
                if (c1 + c2 + c3 == 0) {
                    sum += 1;
                }
            }

        }
    }
    
    cout << sum << endl;

    return 0;
}