#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
int n;
int man[10005];
long long res=0;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    cin >> n;
    for(int i=0; i<n; i++) {
        cin >> man[i];
    }
    sort(man,man+n);
    for(int  i=0; i<n; i++){
        for(int j=i+1; j<n; j++) {
            int sum=man[i]+man[j];
            auto low=lower_bound(man+j+1,man+n,-sum);
            auto high=upper_bound(man+j+1,man+n,-sum);
            res+=high-low;
        }
    }
    cout<< res;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: