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
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#define st first
#define nd second
typedef long long ll;
using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n; cin >> n;
    vector<int> a(n), pref(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        pref[i] = a[i];
    }
    for (int i = 1; i < n; i++) pref[i] += pref[i-1];
    vector<int> b;
    for (int i = 0; i < n; i++) {
        for (int j = i; j < n; j++) {
            if (i == 0) b.push_back(pref[j]);
            else b.push_back(pref[j]-pref[i-1]);
        }
    }
    int shift = 10000000;
    vector<ll>cnt(20000005);
    ll ans = 0;
    for (int i = 0; i < b.size(); i++) {
        ans += cnt[b[i]*-1+shift];
        for (int j = 0; j < i; j++) {
            cnt[b[i]+b[j]+shift]++;
        }
    }
    cout << ans << '\n';
}