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
#include <bits/stdc++.h>
using namespace std;
#define rep(a, b) for (int a = 0; a < (b); a++)
#define rep1(a, b) for (int a = 1; a <= (b); a++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MOD = 1e9 + 7;

#define LOCAL false

const int MAX_N = 507;
const int MAX_SUM = 1e7 + 7;
int n;

int nums[MAX_N];
int prefsum[MAX_N];
int sumrange(int l, int r) {
    return prefsum[r+1]-prefsum[l];
}

int cnt[2*MAX_SUM];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    if (LOCAL) {
        ignore=freopen("io/in", "r", stdin);
        ignore=freopen("io/out", "w", stdout);
    }

    cin >> n;
    rep(i, n) cin >> nums[i];
    rep1(i, n) prefsum[i] = prefsum[i-1]+nums[i-1];

    for (int i = 0; i < n; i++) for (int j = i; j < n; j++) cnt[MAX_SUM+sumrange(i, j)]++;

    int ans = 0;
    for (int i = 0; i < n; i++) for (int j = i; j < n; j++) {
        for (int ii = 0; ii < n; ii++) for (int jj = ii; jj < n; jj++) {
            if (i == ii && j == jj) continue;
            int s1 = sumrange(i, j);
            int s2 = sumrange(ii, jj);
            int rem = -(s1+s2);
            // if (i == 0 && ii == 2 && j == 2 && jj == 2) cout << rem << "??\n";
            // if (cnt[MAX_SUM+rem] != 0) cout << i << ' ' << j << ' ' << ii << ' ' << jj << " ->" << cnt[MAX_SUM+rem] << '\n';
            ans += cnt[MAX_SUM+rem];
            if (s1 == rem) ans--;
            if (s2 == rem) ans--;
        }
    }
    cout << ans/6 << '\n';

    return 0;
}