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
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

#define FOR(i, n) for (int i = 0; i < n; ++i)
#define f first
#define s second
#define pb push_back
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define czas std::chrono::steady_clock::now()
#define cnt std::chrono::duration_cast<std::chrono::microseconds>(czas - beg).count() * 1e-6

using vi = vector<int>;
using ll = long long;
using ull = unsigned long long;
using pll = pair<ll, ll>;
using pull = pair<ull, ull>;
using vll = vector<ll>;
using ii = pair<int, int>;

const int MAX = 3 * 20000 * 500 + 6;
int mapa[MAX * 2];

void solve()
{
    int n;
    cin >> n;

    vi pref;
    pref.pb(0);

    for (int i = 0; i < n; i++)
    {
        int temp;
        cin >> temp;
        pref.pb(pref.back() + temp);
    }

    ll ans = 0;

    for (int sr = sz(pref) - 1; sr >= 0; sr--)
    {
        for (int pocz = 0; pocz < sz(pref); ++pocz)
        {
            for (int kon = pocz + 1; kon < sz(pref); ++kon)
            {
                // cout << "POCZ KON SR " << pocz << ' ' << kon << ' ' << sr << ' ' << mapa[pref[sr] + pref[pocz] - pref[kon]] << '\n';
                ans += mapa[MAX + pref[sr] + pref[pocz] - pref[kon]];
            }
        }
        for (int pocz = 0; pocz < sz(pref); ++pocz)
        {
            for (int kon = pocz + 1; kon < sz(pref); ++kon)
            {
                mapa[MAX + pref[kon] + pref[sr] - pref[pocz]]++;
            }
        }
    }

    unordered_map<int, int> ile;
    for (int i = 0; i < sz(pref); i++)
    {
        for (int j = i + 1; j < sz(pref); j++)
        {
            ile[pref[j] - pref[i]]++;
        }
    }

    for (auto & [val, quant] : ile)
    {
        if (val != 0)
        {
            if (ile.count(-2 * val))
            {
                // cout << "uyyy " << quant << ' ' << ile[-2 * val] << '\n';
                ans -= 1ll * 3 * quant * ile[-2 * val];
            }
        }
        else
        {
            // cout << "zero " << quant << '\n';
            ans -= quant;
            ans -= 1ll * 3 * quant * (quant - 1);
        }
    }

    cout << ans / 6 << '\n';
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    int tests = 1;
    // cin >> tests;

    for (int test = 1; test <= tests; test++)
    {
        solve();
    }

    return 0;
}