stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



int main(){

  int n;

  cin >> n; 

  vector<int> l(n),L(100000);

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

    cin >> l.at(i);

    L.at(l.at(i))++;

  }

  

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

  long long ans =0;

  

  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(l.at(k) < l.at(i) + l.at(j)){

          ans++;

        }

      }

    }

  }

  

  cout << ans << endl;

  return 0;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;



int main(){

  int n;

  cin >> n; 

  vector<int> l(n);

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

    cin >> l.at(i);

  }

  

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

  long long ans =0;

  

  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(l.at(k) < l.at(i) + l.at(j)){

          ans++;

        }

      }

    }

  }

  

  cout << ans << endl;

  return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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);

}

// Optimized solution to the same problem (faster):
#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);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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.

//




// Optimized solution to the same problem (faster):
#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);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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);



}

// Optimized solution to the same problem (faster):
#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);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;   

}

// Optimized solution to the same problem (faster):
#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);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



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

#define SIZE(v)			((int)((v).size()))

#define LOG(x)			log((double)x)

#define TOLOWER(x)          transform(all(x),x.begin(),::tolower)

#define TOUPPER(x)          transform(all(x),x.begin(),::toupper)

#define ROUND(x,m)			(round((double)x/m)*m)

#define DIGITS(x)			(floor(log10((double)x))+1)

#define READSTR(x)			getline(cin,x)

#define sort_g(a,b)              sort(a, b, greater<int>());

#define IOS() ios_base::sync_with_stdio(0);cin.tie(NULL);

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

#define FILE_INPUT() 	freopen( "input.txt", "r", stdin)

#define FILE_OUTPUT()   freopen( "output.txt", "w", stdout)



typedef long long ll;



bool myCmp(pair<int,int> &p1 , pair<int,int>&p2)

{

    return p1.first > p2.first;

}

unsigned long long

choose(unsigned long long n, unsigned long long k) {

    if (k > n) {

        return 0;

    }

    unsigned long long r = 1;

    for (unsigned long long d = 1; d <= k; ++d) {

        r *= n--;

        r /= d;

    }

    return r;

}

int toInt(string str)

{

    int num;

    std::istringstream iss(str); //put string in input stream

    iss >> num; return num; //read from stream as integer

}

ll  OO = 10e9;



const int MAXN = 2*10e3 + 1;

int X[MAXN];

ll cnt = 0;

int main() {

    IOS();

    int n;

    cin>>n;

    REP(i,n) cin>>X[i];



    if(n <= 2)

    {

        cout<<0<<endl;

        return 0;

    }

    //we need to form acute angle triange

    sort(X,X+n);

    //get a and b and check if exits

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

    {

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

        {

            if(i == j) continue;

            auto mn = X[j] - X[i];

            int ub =  upper_bound(X,X+n,mn) - X;

            if(ub == n) continue;

            int lb = lower_bound(X,X+n,X[i]+X[j]) - X;

            if(lb == 0) continue;

            lb--;

            cnt+= (lb-ub + 1);

            if( (i <= lb) && (i >= ub)) cnt--;

            if( (j <= lb) && (j >= ub)) cnt--;

        }

    }

    cout<<cnt/3<<endl;

    return 0;

}




// Optimized solution to the same problem (faster):
#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);

}

// Fastest known solution for this problem: