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
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int MAXN = 1e2 * 5 + 10, MAXM = 1e5 * 2 + 1e4 * 5 + 10, MAXV = 1e7 * 3, ADD = 10000010;
ll A[MAXN], B[MAXM], O[MAXV];
ll pre[MAXN];

ll solve(int n){
    for (int i = 0; i < n; i++){
        pre[i] = (i > 0 ? pre[i-1] : 0) + A[i];
    }
    int idx = 0;
    for (int i = 0; i < n; i++){
        for (int j = i; j < n; j++){
            B[idx] = pre[j] - (i > 0 ? pre[i-1] : 0);
            idx++;
        }
    }
    int m = idx;
    ll ans = 0;
    for (int i = 0; i < m; i++){
        for (int j = i + 1; j < m; j++){
            ll cur = 0 - (B[i] + B[j]);
            ans += O[cur+ADD];
        }
        O[B[i]+ADD]++;
    }
    return ans;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> A[i];
    }
    cout << solve(n) << "\n";
}