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
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("tune=native")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>


#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace __gnu_pbds;
using namespace std;

typedef complex<double> C;
typedef vector<double> vd;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pb push_back
#define st first
#define nd second
typedef long long ll;
typedef long double ld;
const ll I = 1000LL * 1000LL * 1000LL * 1000LL * 1000LL * 1000LL;
const ll M = 1000LL * 1000LL * 1000LL + 7LL;
int K = 30 * 1000 * 1000;
const int N = 60 * 1000 * 1000 + 7;
bitset<N> vis;
int tab[507];
ll il[N];
int hl[N];

ll Deal(int i)
{
    int od = -(2 * i) + K;
    i += K;
    vis[i] = 1;
    if(od < 0 || od >= N)
        return 0LL;
    return -((ll)hl[i] * (ll)hl[od] * 3LL);
}

ll Deal0(ll il)
{
    ll ans = -(il + il * (il - 1) * 3LL);
    return ans;
}

void GenIN(int n)
{
    srand(clock());
    for(int i = 1; i <= n; ++i)
        tab[i] = rand() % (10 * 1000 + 1) - 5 * 1000;
}

void Solve()
{
    int n;
    ll ans = 0LL;
    cin >> n;
    //GenIN(n);
    for(int i = 1; i <= n; ++i)
    {
        cin >> tab[i];
        int cur = 0;
        for(int j = i; j >= 1; --j)
        {
            cur += tab[j];
            ++hl[cur + K];
        }
    }
    int as = 0;
    for(int i = 0; i <= n; ++i)
    {
        as += tab[i];
        int cur;
        for(int j = 1; j <= n; ++j)
        {
            cur = as;
            for(int k = j; k <= n; ++k)
            {
                cur += tab[k];
                ans += il[-cur + K];
            }
        }
        for(int j = 1; j <= n; ++j)
        {
            cur = -as;
            for(int k = j; k <= n; ++k)
            {
                cur += tab[k];
                ++il[cur + K];
            }
        }
    }
   // cout << ans << "\n";
    for(int i = 1; i <= n; ++i)
    {
        int cur = 0;
        for(int j = i; j >= 1; --j)
        {
            cur += tab[j];
            if(cur != 0 && vis[cur + K] == 0)
                ans += Deal(cur);
        }
    }
    ans += Deal0(hl[K]);
    cout << ans / 6LL << "\n";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //int t; cin >> t;
    //while(t--)
        Solve();

    return 0;
}