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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <bits/stdc++.h>
using namespace std;
#define ll long long
struct suma2 {
    int pierwszy;
    int drugi;
    int suma;
};
bool mysort(suma2 a, suma2 b) {
    return a.suma < b.suma;
}

int findIndex(vector<suma2> vec, int sz) {
    int left = 0, right = vec.size() - 1, result = -1;
    while (left <= right) {
        int mid = left + (right - left) / 2;
        if (vec[mid].suma == sz) {
            result = mid;
            right = mid - 1;
        }
        else if (vec[mid].suma < sz) left = mid + 1;
        else right = mid - 1;
    }
    return result;
}

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

    int n;
    cin >> n;
    int ucb[n];
    for (int i=0; i<n; i++) {
        int a;
        cin >> a;
        ucb[i] = a;
    }
    vector<int> bucb;
    for (int i=0; i<n; i++) {
        int maxDl = n-i;
        for (int j=1; j<=maxDl; j++) {
            int sum = 0;
            for (int k=0; k<j; k++) {
                sum += ucb[i+k];
            }
            bucb.push_back(sum);
        }
    }

    vector<suma2> suma2Vec;
    for (int i=0; i<bucb.size(); i++) {
        for (int j=i+1; j<bucb.size(); j++) {
            int sum = bucb[i] + bucb[j];
            suma2 s;
            s.pierwszy = i;
            s.drugi = j;
            s.suma = sum;
            suma2Vec.push_back(s);
        }
    }

    sort(suma2Vec.begin(), suma2Vec.end(), mysort);
    ll cnt = 0;
    for (int i=0; i<bucb.size(); i++) {
        int a = bucb[i];
        int szukanaSuma = -a;
        int idxBeg = findIndex(suma2Vec, szukanaSuma);
        if (idxBeg != -1) {
            while (suma2Vec[idxBeg].suma == szukanaSuma) {
                suma2 s = suma2Vec[idxBeg];
                if (s.pierwszy < s.drugi && s.drugi < i) {
                    cnt++;
                }
                idxBeg++;
            }
        }
    }
    cout << cnt;
    return 0;
}