stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <iostream>

#include <cstdio>

#include <algorithm>

#include <vector>



using namespace std;

int main()

{

    int n; cin >> n;

    vector< int > v(n);

    for( auto &i : v ) cin >> i;

    sort( v.begin(), v.end() );

    int ans = 0;

    for( int i = 0; i < n; ++ i )

    {

        for( int j = i + 1; j < n; ++ j )

        {

            int L = v[i] + v[j];

            int l = j, r = n - 1;

            while( l < r )

            {

                int mid = ( l + r + 1 ) >> 1;

                if( v[mid] < L )

                    l = mid;

                else r = mid - 1;

            }

            ans += l - j;

        }

    }

    cout << ans << endl;

}

// Faster C++ solution for the same problem (measured speedup: 5.034960187304249x):
#include<stdio.h>

#include<stdlib.h>

int inc(const void *a, const void *b)

{

	return *(int *)a-*(int *)b;

}

int main()

{

	int n,a[10000],l=0,r=1,m,cnt=0;

	scanf("%d",&n);

	for(int i=0;i<n;i++)scanf("%d",&a[i]);

	qsort(a,n,sizeof(int),inc);

	m=2;

	for(int i=0;i<n-2;i++)

	{

		for(int j=i+1;j<n-1;j++)

		{

			for(int k=j+1;k<n;k++)

			{

				if(a[i]+a[j]>a[k])cnt++;

			}

		}

	}

	printf("%d\n",cnt);

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

const int maxn = 2e5+10;

typedef long long ll;

int raw[maxn];

int main(){

	int n;

	ll ans = 0;

	scanf("%d",&n);

	for(int i = 1;i <= n;i++)scanf("%d",&raw[i]);

	sort(&raw[1],&raw[n+1]);

	for(int i = 1;i <= n;i++)

		for(int j = i;j <= n;j++)

			if(i != j){

				int a = raw[i],b = raw[j];

				int L = max(a-b,b-a),R = a+b;

				int x = upper_bound(&raw[1],&raw[n+1],L)-raw;

				int y = lower_bound(&raw[1],&raw[n+1],R)-raw;

				ans += (y-x) > 0?y-x:0;

				if(x <= i and i <= y)ans--;

				if(x <= j and j <= y)ans--;

//				cout << ans << endl;

			}

	printf("%lld\n",ans/3);

}

// Faster C++ solution for the same problem (measured speedup: 4.964537210391578x):
#include<stdio.h>

#include<stdlib.h>

int inc(const void *a, const void *b)

{

	return *(int *)a-*(int *)b;

}

int main()

{

	int n,a[10000],l=0,r=1,m,cnt=0;

	scanf("%d",&n);

	for(int i=0;i<n;i++)scanf("%d",&a[i]);

	qsort(a,n,sizeof(int),inc);

	m=2;

	for(int i=0;i<n-2;i++)

	{

		for(int j=i+1;j<n-1;j++)

		{

			for(int k=j+1;k<n;k++)

			{

				if(a[i]+a[j]>a[k])cnt++;

			}

		}

	}

	printf("%d\n",cnt);

}
// Slower C++ solution:
#include <iostream>//

#include <algorithm>

#include <set>



int n;

int a[2020];



using namespace std;



struct tri {

    int a, b, c;



    tri(int aa, int bb, int cc) {

        a = aa;

        b = bb;

        c = cc;

    }

};



bool operator<(tri aa, tri bb) {

    if (aa.c < bb.c)

        return true;

    else if (aa.c == bb.c) {

        if (aa.b < bb.b)

            return true;

        else if (aa.b == bb.b) {

            if (aa.a < bb.a)

                return true;

        }

    }

    return false;

}



set<tri> ss, s2;



int main() {

    int n;

    long long cnt = 0;

    cin >> n;

    for (int i = 0; i < n; ++i)

        cin >> a[i];

    sort(a, a + n);

/*

    for (int i = 0; i < n; ++i) {

        for (int j = i + 1; j < n; ++j) {

            for (int k = j + 1; k < n; ++k) {

                if (a[k] < a[i] + a[j]) {

                    tri t = tri(a[i], a[j], a[k]);

                    ss.insert(t);

                }

            }

        }

    }

*/



    for (int i = 0; i < n; ++i) {

        for (int j = i + 1; j < n; ++j) {

            for (int k = j + 1; k < n; ++k) {

                if (a[k] < a[i] + a[j]) {

                    ++cnt;

                }

            }

        }

    }



    //cout << ss.size() << endl;

    //cout << s2.size() << endl;

    cout << cnt;



    return 0;

}

// Created by Kevin Weng on 2019/10/28.

//




// Faster C++ solution for the same problem (measured speedup: 4.977722767640878x):
#include<stdio.h>

#include<stdlib.h>

int inc(const void *a, const void *b)

{

	return *(int *)a-*(int *)b;

}

int main()

{

	int n,a[10000],l=0,r=1,m,cnt=0;

	scanf("%d",&n);

	for(int i=0;i<n;i++)scanf("%d",&a[i]);

	qsort(a,n,sizeof(int),inc);

	m=2;

	for(int i=0;i<n-2;i++)

	{

		for(int j=i+1;j<n-1;j++)

		{

			for(int k=j+1;k<n;k++)

			{

				if(a[i]+a[j]>a[k])cnt++;

			}

		}

	}

	printf("%d\n",cnt);

}
// Slower C++ solution:
#include <iostream>

#include <algorithm>

using namespace std;



int comp(const int &a, const int &b)

{

	return (a > b);

}



int main()

{

	int n, l[10000];

	int sum = 0;

	

	cin >> n;

	

	for(int i = 0; i < n; i++)

		cin >> l[i];

	sort(l, l + n, comp);

	

	for(int i = 0; i < n - 2; i++)

	{

		int L = i + 1;

		int R = n - 1;

		while(L < R)

		{

			if(l[i] < l[L] + l[R])

			{

				sum += R - L;

				L++;

			}

			else

				R--;

		}

	}

	

	cout << sum << endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.9853062077043955x):
#include<stdio.h>

#include<stdlib.h>

int inc(const void *a, const void *b)

{

	return *(int *)a-*(int *)b;

}

int main()

{

	int n,a[10000],l=0,r=1,m,cnt=0;

	scanf("%d",&n);

	for(int i=0;i<n;i++)scanf("%d",&a[i]);

	qsort(a,n,sizeof(int),inc);

	m=2;

	for(int i=0;i<n-2;i++)

	{

		for(int j=i+1;j<n-1;j++)

		{

			for(int k=j+1;k<n;k++)

			{

				if(a[i]+a[j]>a[k])cnt++;

			}

		}

	}

	printf("%d\n",cnt);

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int main(){

    int n,q,a[1000009],x;

    cin >> n;

    for(int i=1; i<=n; i++){

        cin >> a[i];

    }

    sort(a+1,a+n+1);

    long long jum=0;

    for(int i=1; i<=n; i++){

    	for(int j=i+1; j<=n; j++){

    		jum+=lower_bound(a+j+1,a+n+1,a[i]+a[j])-a-j-1;

    	}

    }

    cout << jum << endl;

}

// Faster C++ solution for the same problem (measured speedup: 5.440975763988683x):
#include<stdio.h>

#include<stdlib.h>

int inc(const void *a, const void *b)

{

	return *(int *)a-*(int *)b;

}

int main()

{

	int n,a[10000],l=0,r=1,m,cnt=0;

	scanf("%d",&n);

	for(int i=0;i<n;i++)scanf("%d",&a[i]);

	qsort(a,n,sizeof(int),inc);

	m=2;

	for(int i=0;i<n-2;i++)

	{

		for(int j=i+1;j<n-1;j++)

		{

			for(int k=j+1;k<n;k++)

			{

				if(a[i]+a[j]>a[k])cnt++;

			}

		}

	}

	printf("%d\n",cnt);

}
// Slower C++ solution:
#include <iostream>

#include <algorithm>

using namespace std; 

int n, ans, a[100001];

int main(){

	cin >> n;

	for (int i = 1;i <= n;i++) 

	    cin >> a[i];

	sort(a + 1, a + n + 1);

    for (int i = 1; i <= n; i++)

        for (int j = i + 1; j <= n; j++)

            for (int k = j + 1; k <= n; k++) {

                if (a[i] + a[j] <= a[k] || 

                    a[i] + a[k] <= a[j] ||

                    a[j] + a[k] <= a[i] ) break;

                ans++;

            }

//    int cur = 1;

//    while (cur <= n - 2) {

//        for (int i = 1; i <= n - 1 -cur; i++) {

//            ans += upper_bound(a + cur + i + 2, a + n + 1, a[cur] + a[cur + i]) - a - cur - i - 1;

//            cout << ans << endl;

//        }

//        cur++;

//    }

    cout << ans;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.977339347078854x):
#include<stdio.h>

#include<stdlib.h>

int inc(const void *a, const void *b)

{

	return *(int *)a-*(int *)b;

}

int main()

{

	int n,a[10000],l=0,r=1,m,cnt=0;

	scanf("%d",&n);

	for(int i=0;i<n;i++)scanf("%d",&a[i]);

	qsort(a,n,sizeof(int),inc);

	m=2;

	for(int i=0;i<n-2;i++)

	{

		for(int j=i+1;j<n-1;j++)

		{

			for(int k=j+1;k<n;k++)

			{

				if(a[i]+a[j]>a[k])cnt++;

			}

		}

	}

	printf("%d\n",cnt);

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<algorithm>

#include<cstring>

using namespace std;

#define maxn 100010

int tmp[10];

int a[maxn];

bool check(int m,int n,int z)

{



	int sum=m+n;

	if(sum>z)

	return true;

	return false;

	

}

int main()

{

	int n;

	cin>>n;

	for(int i=1;i<=n;i++)

	{

		scanf("%d",&a[i]);

	}

	sort(a+1,a+1+n);

	int cnt=0;

	for(int i=1;i<=n;i++)

	{

		for(int j=(i+1);j<=n;j++)

		{

			for(int k=(j+1);k<=n;k++)

			{

				

					if(check(a[i],a[j],a[k]))

					{

						cnt++;

					}

				 

			}

		}

	}

     cout<<cnt<<endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.002998488473676x):
#include<stdio.h>

#include<stdlib.h>

int inc(const void *a, const void *b)

{

	return *(int *)a-*(int *)b;

}

int main()

{

	int n,a[10000],l=0,r=1,m,cnt=0;

	scanf("%d",&n);

	for(int i=0;i<n;i++)scanf("%d",&a[i]);

	qsort(a,n,sizeof(int),inc);

	m=2;

	for(int i=0;i<n-2;i++)

	{

		for(int j=i+1;j<n-1;j++)

		{

			for(int k=j+1;k<n;k++)

			{

				if(a[i]+a[j]>a[k])cnt++;

			}

		}

	}

	printf("%d\n",cnt);

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

#define ll long long

const int maxn=5000+100;



ll a[maxn],t[maxn],n,ans;



inline int low_bit(int x){

	return x&(-x);

}

void updata(int i,ll k){

	for(;i<maxn;i+=low_bit(i))t[i]+=k;

}

int query(int i){

	ll ans=0;

	for(;i>0;i-=low_bit(i))ans+=t[i];

	return ans;

}



int main(){

	memset(t,0,sizeof(t));

	scanf("%lld",&n);



	for(int i=0;i<n;i++){

		scanf("%lld",&a[i]);

		updata(a[i],1);

	}

	ans=0;

	sort(a,a+n);

	for(int i=0;i<n;i++)

		for(int j=i+1;j<n;j++){

			int r=a[i]+a[j]-1,l=a[i]-a[j];

			if(l<0)l=-l;

			int tmp=query(r)-query(l);

			if(l<a[i]&&a[i]<=r)tmp--;

			if(l<a[j]&&a[j]<=r)tmp--;

			if(tmp>0)ans+=tmp;

		}

			

	printf("%lld\n",ans/3);



}

// Faster C++ solution for the same problem (measured speedup: 5.159752462143875x):
#include<stdio.h>

#include<stdlib.h>

int inc(const void *a, const void *b)

{

	return *(int *)a-*(int *)b;

}

int main()

{

	int n,a[10000],l=0,r=1,m,cnt=0;

	scanf("%d",&n);

	for(int i=0;i<n;i++)scanf("%d",&a[i]);

	qsort(a,n,sizeof(int),inc);

	m=2;

	for(int i=0;i<n-2;i++)

	{

		for(int j=i+1;j<n-1;j++)

		{

			for(int k=j+1;k<n;k++)

			{

				if(a[i]+a[j]>a[k])cnt++;

			}

		}

	}

	printf("%d\n",cnt);

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

#define vi vector<int>

#define ll long long

#define pb push_back

#define fi first

#define se second

#define ii pair<int,int>

const int MOD = 1e9 + 7;



int main() {

   ios_base::sync_with_stdio(0); cin.tie(0);

   int n; vector<int> l;

   cin>>n;

   for(int i =0;i<n;i++) {

   		int x;

   		cin>>x;

   		l.pb(x);

   }

   sort(l.begin(),l.end());

   int ans = 0;

   for(int i =0;i<n;i++) {

   	for(int j = i+1;j<n;j++) {

   		for(int k = j+1;k<n;k++) {

   			if(l[i] + l[j] > l[k])

   				ans++;

   		}

   	}

   }

   cout<<ans<<"\n";

  

   return 0;   

}

// Faster C++ solution for the same problem (measured speedup: 5.103596548556686x):
#include<stdio.h>

#include<stdlib.h>

int inc(const void *a, const void *b)

{

	return *(int *)a-*(int *)b;

}

int main()

{

	int n,a[10000],l=0,r=1,m,cnt=0;

	scanf("%d",&n);

	for(int i=0;i<n;i++)scanf("%d",&a[i]);

	qsort(a,n,sizeof(int),inc);

	m=2;

	for(int i=0;i<n-2;i++)

	{

		for(int j=i+1;j<n-1;j++)

		{

			for(int k=j+1;k<n;k++)

			{

				if(a[i]+a[j]>a[k])cnt++;

			}

		}

	}

	printf("%d\n",cnt);

}
// Slower C++ solution:
#include "bits/stdc++.h"



using namespace std;

typedef long long ll;

typedef vector<ll> vll;

#define int ll

#define fi first

#define se second

#define SORT(a) sort(a.begin(),a.end())

#define rep(i,n) for(int i = 0;i < (n) ; i++)

#define REP(i,n) for(int i = 0;i < (n) ; i++)

#define MP(a,b) make_pair(a,b)

#define pb(a) push_back(a)

#define INF LLONG_MAX/2

#define all(x) (x).begin(),(x).end()

#define debug(x) cerr<<#x<<": "<<x<<endl

#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl

int MOD = 998244353;

signed main(){



    int n;

	cin >> n;

	vll l(n);

	rep(i,n)cin >> l[i];

	l.pb(-1);

	l.pb(INF);

	SORT(l);



	int ans = 0;



	for(int i = 1;i <= n-2;i++){

		for(int j = i+1;j <= n-1;j++){

			int mini = abs(l[i]-l[j]);

			int maxi = l[i]+l[j];

			int L,R;

			ll ok = n+1;

			ll ng = 0;



			while(abs(ok-ng)>1){

				ll mid = (ok+ng)/2;

				if(mini < l[mid]){

					ok = mid;

				}else{

					ng = mid;

				}

			}

			L = ok;



			ok = 0;

			ng = n+1;



			while(abs(ok-ng)>1){

				ll mid = (ok+ng)/2;

				if(l[mid] < maxi){

					ok = mid;

				}else{

					ng = mid;

				}

			}

			R = ok;

			L = max(L,j+1);

			if(R == n+1 || L == 0 || L > R)continue;

			else ans += R-L+1;

		}

	}

	cout << ans << endl;

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.039735216915052x):
#include<stdio.h>

#include<stdlib.h>

int inc(const void *a, const void *b)

{

	return *(int *)a-*(int *)b;

}

int main()

{

	int n,a[10000],l=0,r=1,m,cnt=0;

	scanf("%d",&n);

	for(int i=0;i<n;i++)scanf("%d",&a[i]);

	qsort(a,n,sizeof(int),inc);

	m=2;

	for(int i=0;i<n-2;i++)

	{

		for(int j=i+1;j<n-1;j++)

		{

			for(int k=j+1;k<n;k++)

			{

				if(a[i]+a[j]>a[k])cnt++;

			}

		}

	}

	printf("%d\n",cnt);

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int main()

{

    int n,lol=0;



    cin>>n;

    vector<int> a;

    for(int i = 0; i<n; i++)

    {

        int x;

        cin>>x;

        a.push_back(x);

    }

    sort(a.begin(), a.end());

    long long  cnt = 0;

    for(int i = 0; i<n; i++) for(int j = i+1; j<n-1; j++)

        {

            lol = upper_bound(a.begin(), a.end(), a[i]+a[j]-1) - a.begin()-1;

            cnt+= lol - j;

        }

    cout  << cnt << endl;

}


// Faster C++ solution for the same problem (measured speedup: 5.037581315984782x):
#include<stdio.h>

#include<stdlib.h>

int inc(const void *a, const void *b)

{

	return *(int *)a-*(int *)b;

}

int main()

{

	int n,a[10000],l=0,r=1,m,cnt=0;

	scanf("%d",&n);

	for(int i=0;i<n;i++)scanf("%d",&a[i]);

	qsort(a,n,sizeof(int),inc);

	m=2;

	for(int i=0;i<n-2;i++)

	{

		for(int j=i+1;j<n-1;j++)

		{

			for(int k=j+1;k<n;k++)

			{

				if(a[i]+a[j]>a[k])cnt++;

			}

		}

	}

	printf("%d\n",cnt);

}
// Slower C++ solution:
#include<iostream>

#include<algorithm>

int n,d[30000];



bool bh(int i,int j,int k){

    if (d[i]<d[j]+d[k]){

        return true;

    }

    return false;

}



int main(){

    std::cin>>n;

    for (int i=1;i<=n;i++){

        std::cin>>d[i];

    }

    int sl=0;

    std::sort(d+1,d+n+1);

    for (int i=1;i<=n-2;i++){

        for (int j=i+1;j<=n-1;j++){

            for (int k=j+1;k<=n;k++){

                if ((bh(i,j,k)) && (bh(j,k,i)) && (bh(k,i,j))){

                sl++;}

                else break;

            }

        }

    }

    std::cout<<sl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.209856344368015x):
#include<cstring>

#include<algorithm>

#include<cstdio>

#define N 20005



using namespace std;

int a[N],n;

bool cmp(int a,int b){

return a>b;

}



int sol(int x,int y,int l,int r){

if(l==r){

if(y+a[l]>x)return l;

else return -1;

}

int md=(l+r)/2;

if(y+a[md+1]<=x)return sol(x,y,l,md);

else return sol(x,y,md+1,r);

}

int main(){

scanf("%d",&n);

for(int i=1;i<=n;i++){

scanf("%d",&a[i]);

}

sort(a+1,a+n+1,cmp);

long long int ans=0;

for(int i=1;i<=n;i++){

for(int j=i+1;j<=n-1;j++){

int as=sol(a[i],a[j],j+1,n);

if(as>j)ans+=(long long int )(as-j);

}

}

printf("%lld",ans);

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



const int N = (int)2e3;

int dat[N+5];



int main() {

    int n; scanf("%d", &n);

    for (int i=1; i<=n; i++) scanf("%d", dat+i);



    sort(dat+1, dat+1+n);



    long long res = 0;

    for (int i=1; i<=n; i++) for (int j=i+1; j<=n; j++) {

        int key = dat[i] + dat[j];

        int idx = lower_bound(dat+1, dat+1+n, key) - dat;

        res += (long long)max(idx-j - 1, 0);

    }



    printf("%lld\n", res);

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.149946016210875x):
#include<cstring>

#include<algorithm>

#include<cstdio>

#define N 20005



using namespace std;

int a[N],n;

bool cmp(int a,int b){

return a>b;

}



int sol(int x,int y,int l,int r){

if(l==r){

if(y+a[l]>x)return l;

else return -1;

}

int md=(l+r)/2;

if(y+a[md+1]<=x)return sol(x,y,l,md);

else return sol(x,y,md+1,r);

}

int main(){

scanf("%d",&n);

for(int i=1;i<=n;i++){

scanf("%d",&a[i]);

}

sort(a+1,a+n+1,cmp);

long long int ans=0;

for(int i=1;i<=n;i++){

for(int j=i+1;j<=n-1;j++){

int as=sol(a[i],a[j],j+1,n);

if(as>j)ans+=(long long int )(as-j);

}

}

printf("%lld",ans);

}
// Slower C++ solution:
#include<cstdio>

#include<algorithm>

#include<iostream>

#include<cmath>

#include<cstring>

#include<string>

using namespace std;

int n,cnt=0,l[100010];

int main(){

	scanf("%d",&n);

	for(int i=1;i<=n;i++)

	    scanf("%d",&l[i]);

	sort(l+1,l+n+1);

	for(int i=1;i<=n;i++)

	    for(int j=1;j<i;j++){

	    	int left=i+1,right=n,mid,ans=-1;

	    	while(left<=right){

	    		mid=(left+right)/2;

	    		if(l[mid]<l[i]+l[j]&&(mid==n||l[mid+1]>=l[i]+l[j])){ans=mid;break;}

				else if(l[mid]>=l[i]+l[j]) right=mid-1;

				else left=mid+1;

			}

			if(ans==-1) continue;

			else cnt+=(ans-i);

		}

	cout<<cnt<<endl;

}

// Faster C++ solution for the same problem (measured speedup: 5.21276852013343x):
#include<cstring>

#include<algorithm>

#include<cstdio>

#define N 20005



using namespace std;

int a[N],n;

bool cmp(int a,int b){

return a>b;

}



int sol(int x,int y,int l,int r){

if(l==r){

if(y+a[l]>x)return l;

else return -1;

}

int md=(l+r)/2;

if(y+a[md+1]<=x)return sol(x,y,l,md);

else return sol(x,y,md+1,r);

}

int main(){

scanf("%d",&n);

for(int i=1;i<=n;i++){

scanf("%d",&a[i]);

}

sort(a+1,a+n+1,cmp);

long long int ans=0;

for(int i=1;i<=n;i++){

for(int j=i+1;j<=n-1;j++){

int as=sol(a[i],a[j],j+1,n);

if(as>j)ans+=(long long int )(as-j);

}

}

printf("%lld",ans);

}
// Slower C++ solution:
#include <iostream>

#include <cstdio>

#include <algorithm>

#include <vector>



using namespace std;

int main()

{

    int n; cin >> n;

    vector< int > v(n);

    for( auto &i : v ) cin >> i;

    sort( v.begin(), v.end() );

    int ans = 0;

    for( int i = 0; i < n; ++ i )

    {

        for( int j = i + 1; j < n; ++ j )

        {

            int L = v[i] + v[j];

            int l = j, r = n - 1;

            while( l < r )

            {

                int mid = ( l + r + 1 ) >> 1;

                if( v[mid] < L )

                    l = mid;

                else r = mid - 1;

            }

            ans += l - j;

        }

    }

    cout << ans << endl;

}

// Faster C++ solution for the same problem (measured speedup: 5.2693911915661955x):
#include<cstring>

#include<algorithm>

#include<cstdio>

#define N 20005



using namespace std;

int a[N],n;

bool cmp(int a,int b){

return a>b;

}



int sol(int x,int y,int l,int r){

if(l==r){

if(y+a[l]>x)return l;

else return -1;

}

int md=(l+r)/2;

if(y+a[md+1]<=x)return sol(x,y,l,md);

else return sol(x,y,md+1,r);

}

int main(){

scanf("%d",&n);

for(int i=1;i<=n;i++){

scanf("%d",&a[i]);

}

sort(a+1,a+n+1,cmp);

long long int ans=0;

for(int i=1;i<=n;i++){

for(int j=i+1;j<=n-1;j++){

int as=sol(a[i],a[j],j+1,n);

if(as>j)ans+=(long long int )(as-j);

}

}

printf("%lld",ans);

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

const int maxn = 2e5+10;

typedef long long ll;

int raw[maxn];

int main(){

	int n;

	ll ans = 0;

	scanf("%d",&n);

	for(int i = 1;i <= n;i++)scanf("%d",&raw[i]);

	sort(&raw[1],&raw[n+1]);

	for(int i = 1;i <= n;i++)

		for(int j = i;j <= n;j++)

			if(i != j){

				int a = raw[i],b = raw[j];

				int L = max(a-b,b-a),R = a+b;

				int x = upper_bound(&raw[1],&raw[n+1],L)-raw;

				int y = lower_bound(&raw[1],&raw[n+1],R)-raw;

				ans += (y-x) > 0?y-x:0;

				if(x <= i and i <= y)ans--;

				if(x <= j and j <= y)ans--;

//				cout << ans << endl;

			}

	printf("%lld\n",ans/3);

}

// Faster C++ solution for the same problem (measured speedup: 5.195689275280303x):
#include<cstring>

#include<algorithm>

#include<cstdio>

#define N 20005



using namespace std;

int a[N],n;

bool cmp(int a,int b){

return a>b;

}



int sol(int x,int y,int l,int r){

if(l==r){

if(y+a[l]>x)return l;

else return -1;

}

int md=(l+r)/2;

if(y+a[md+1]<=x)return sol(x,y,l,md);

else return sol(x,y,md+1,r);

}

int main(){

scanf("%d",&n);

for(int i=1;i<=n;i++){

scanf("%d",&a[i]);

}

sort(a+1,a+n+1,cmp);

long long int ans=0;

for(int i=1;i<=n;i++){

for(int j=i+1;j<=n-1;j++){

int as=sol(a[i],a[j],j+1,n);

if(as>j)ans+=(long long int )(as-j);

}

}

printf("%lld",ans);

}
// Slower C++ solution:
#include <iostream>//

#include <algorithm>

#include <set>



int n;

int a[2020];



using namespace std;



struct tri {

    int a, b, c;



    tri(int aa, int bb, int cc) {

        a = aa;

        b = bb;

        c = cc;

    }

};



bool operator<(tri aa, tri bb) {

    if (aa.c < bb.c)

        return true;

    else if (aa.c == bb.c) {

        if (aa.b < bb.b)

            return true;

        else if (aa.b == bb.b) {

            if (aa.a < bb.a)

                return true;

        }

    }

    return false;

}



set<tri> ss, s2;



int main() {

    int n;

    long long cnt = 0;

    cin >> n;

    for (int i = 0; i < n; ++i)

        cin >> a[i];

    sort(a, a + n);

/*

    for (int i = 0; i < n; ++i) {

        for (int j = i + 1; j < n; ++j) {

            for (int k = j + 1; k < n; ++k) {

                if (a[k] < a[i] + a[j]) {

                    tri t = tri(a[i], a[j], a[k]);

                    ss.insert(t);

                }

            }

        }

    }

*/



    for (int i = 0; i < n; ++i) {

        for (int j = i + 1; j < n; ++j) {

            for (int k = j + 1; k < n; ++k) {

                if (a[k] < a[i] + a[j]) {

                    ++cnt;

                }

            }

        }

    }



    //cout << ss.size() << endl;

    //cout << s2.size() << endl;

    cout << cnt;



    return 0;

}

// Created by Kevin Weng on 2019/10/28.

//




// Faster C++ solution for the same problem (measured speedup: 5.209488760607029x):
#include<cstring>

#include<algorithm>

#include<cstdio>

#define N 20005



using namespace std;

int a[N],n;

bool cmp(int a,int b){

return a>b;

}



int sol(int x,int y,int l,int r){

if(l==r){

if(y+a[l]>x)return l;

else return -1;

}

int md=(l+r)/2;

if(y+a[md+1]<=x)return sol(x,y,l,md);

else return sol(x,y,md+1,r);

}

int main(){

scanf("%d",&n);

for(int i=1;i<=n;i++){

scanf("%d",&a[i]);

}

sort(a+1,a+n+1,cmp);

long long int ans=0;

for(int i=1;i<=n;i++){

for(int j=i+1;j<=n-1;j++){

int as=sol(a[i],a[j],j+1,n);

if(as>j)ans+=(long long int )(as-j);

}

}

printf("%lld",ans);

}
// Slower C++ solution:
#include <iostream>

#include <algorithm>

using namespace std;



int comp(const int &a, const int &b)

{

	return (a > b);

}



int main()

{

	int n, l[10000];

	int sum = 0;

	

	cin >> n;

	

	for(int i = 0; i < n; i++)

		cin >> l[i];

	sort(l, l + n, comp);

	

	for(int i = 0; i < n - 2; i++)

	{

		int L = i + 1;

		int R = n - 1;

		while(L < R)

		{

			if(l[i] < l[L] + l[R])

			{

				sum += R - L;

				L++;

			}

			else

				R--;

		}

	}

	

	cout << sum << endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.217425290546875x):
#include<cstring>

#include<algorithm>

#include<cstdio>

#define N 20005



using namespace std;

int a[N],n;

bool cmp(int a,int b){

return a>b;

}



int sol(int x,int y,int l,int r){

if(l==r){

if(y+a[l]>x)return l;

else return -1;

}

int md=(l+r)/2;

if(y+a[md+1]<=x)return sol(x,y,l,md);

else return sol(x,y,md+1,r);

}

int main(){

scanf("%d",&n);

for(int i=1;i<=n;i++){

scanf("%d",&a[i]);

}

sort(a+1,a+n+1,cmp);

long long int ans=0;

for(int i=1;i<=n;i++){

for(int j=i+1;j<=n-1;j++){

int as=sol(a[i],a[j],j+1,n);

if(as>j)ans+=(long long int )(as-j);

}

}

printf("%lld",ans);

}