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

using namespace std;

void printv(const vector<int> &wyn) {
	for (auto i: wyn)
		cout << i << " ";
	cout << endl;
}

void mk_buc(const vector<int> &c,vector<vector<int>> &buc) {
	for (int i = 0; i < c.size(); i++) {
		buc.push_back({});
		buc[i].push_back(c[i]);
		for (int j = 1; j < c.size() - i; j++) {
			buc[i].push_back(buc[i][j-1]+c[j+i]);
		}
	}
}

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

	int n, licz;
	vector<int> uc;
	vector<vector<int>> buc2;
	vector<int> buc;
	map<int,vector<int>> liczby;
	cin >> n;
	for (int i=0; i<n; i++) {
		cin >> licz;
		uc.push_back(licz);
	}
	mk_buc(uc, buc2);
	for (auto a: buc2) 
		for(auto i: a)
			buc.push_back(i);
		
	for (int i = 0; i<buc.size(); i++) {
		liczby[buc[i]].push_back(i);
	}
	for (int i = 0; i<buc.size(); i++) {
		sort(liczby[buc[i]].begin(), liczby[buc[i]].end());
	}

	int wynik = 0;
	int sum2 =0;
	auto ff = liczby[buc[0]].end();
	for (int i = 0; i<buc.size(); i++) {
		for (int j = i+1; j<buc.size(); j++) {
			sum2 = -(buc[i]+buc[j]);
			ff = lower_bound(liczby[sum2].begin(), liczby[sum2].end(), j+1);
			if (ff != liczby[sum2].end()) {
				wynik+=(liczby[sum2].end()-ff);
			}
		}
	}
	cout << wynik << "\n";
}