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
#include <iostream>
#include <vector>
using namespace std;

constexpr int A = 10000001;
int T[20000090];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, ans = 0, arr[505];
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> arr[i];
    }
    vector<int> s1;
    for(int i = 0; i < n; i++){
        int sum = 0;
        for(int j = i; j < n; j++){
            sum += arr[j];
            ans += T[A - sum];
            for(auto x : s1) T[x + sum]++;
            s1.push_back(sum + A);
        }
    }
    cout << ans;
    return 0;
}