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

using namespace std;
int n,cnt=0;
long long num[2005];
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    cin  >>  n;
    for(int i=0; i<n; i++) {
        cin >> num[i];
    }
    sort(num,num+n);

    for(int i=0; i<n; i++) {
        int target=num[i];
        int st=0,en=n-1;
        while(st<en) {
            if(st==i) {
                st++;
                continue;
            }
            if(en==i) {
                en--;
                continue;
            }

            if(target<num[st]+num[en]) en-=1;
            else if(target>num[st]+num[en]) st+=1;
            else {
                cnt++;
                break;
            }
        }
    }
    cout << cnt;
}

Embed on website

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