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
#include <bits/stdc++.h>
#define debug(x) cout<<#x<<" = "<<x<<"\n"
#define all(x) x.begin(),x.end()
#define inf 1e18
#define mod 1e9+7
using namespace std;
using ll = long long;
using ld = long double;
template <typename H, typename T>
ostream& operator<<(ostream& os, pair<H, T> m){return os <<"("<< m.first<<", "<<m.second<<")";}
template <typename H>
ostream& operator<<(ostream& os, vector<H> V){os<<"{";for(int i=0; i<(int)V.size(); i++){if(i)os<<" ";os<<V[i];}os<<"}";return os;}
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
int losuj(int a, int b){return rng()%(b-a+1)+a;}

#define rozmiar 510
#define plus 20001000

long long n, p[rozmiar], b;
long long mapka[plus*2], odp;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> b;
        p[i]=p[i-1]+b;
    }
    for(int a=0;a<=n;a++){
        for(int c=0;c<=n;c++){
            for(int d=c+1;d<=n;d++){
                odp+=mapka[plus+p[a]+p[d]-p[c]];
            }
        }
        for(int d=0;d<=n;d++){
            for(int c=d+1;c<=n;c++){
                mapka[plus+p[a]+p[d]-p[c]]++;
            }
        }
    }
    for(int i=0;i<2*plus;i++)mapka[i]=0;
    for(int c=0;c<=n;c++){
        for(int d=c+1;d<=n;d++){
            mapka[plus+(p[d]-p[c])]++;
        }
    }
    for(int c=0;c<=n;c++){
        for(int d=c+1;d<=n;d++){
            if(plus+2*(p[c]-p[d])>=0 && plus+2*(p[c]-p[d])<2*plus)odp-=3*mapka[plus+2*(p[c]-p[d])];
        }
    }
    for(int i=0;i<2*plus;i++)mapka[i]=0;
    for(int a=0;a<=n;a++){
        odp+=mapka[p[a]+plus];
        mapka[p[a]+plus]+=2;
    }
    cout << odp/6 << endl;
    return 0;
}