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

using namespace std;

typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define pb push_back
#define fi first
#define se second
#define rep(i,b,e) for(int i=(b); i<(e); i++)
#define each(a,x)  for(auto &a : (x))
#define all(x) (x).begin(), (x).end()
#define sz(x)  (int)(x).size()

const int A = 10'000'005;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    ll res=0;
    cin >> n;
    vi arr1(n),arr;
    vector<ll> cntPairs(4*A);
    each(x,arr1) cin >> x;
    rep(i,0,n){
        arr.pb(arr1[i]);
        rep(j,i+1,n) arr.pb(arr.back()+arr1[j]);
    }
    n = sz(arr);
    rep(i,0,n){
        res += cntPairs[2*A-arr[i]];
        rep(j,0,i) ++cntPairs[arr[i]+arr[j]+2*A];
    }
    cout << res;
    return 0;
}