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 f first
#define s second
#define ll long long

#pragma GCC optimize("O3","unroll-loops")

constexpr int maxn=500+2;
constexpr int add=10000000;

int n, num;
int a[maxn], pref[maxn];
int ciag[maxn*(maxn+1)/2];

int get(int a,int b)
{
    if(b<a) swap(a,b);
    return pref[b]-pref[a-1];
}

ll ile[2*add+7];
ll solv;

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        pref[i]=pref[i-1]+a[i];
    }

    for(int i=1;i<=n;++i)
    {
        for(int j=i;j<=n;++j)
        {
            num++;
            ciag[num]=get(i,j);
        }
    }

    for(int i=1;i<=num;++i)
    {
        for(int j=i+1;j<=num;++j)
            solv+=ile[-(ciag[i]+ciag[j])+add];
        ile[ciag[i]+add]++;
    }
    cout<<solv;
    return 0;
}