stablegradients/pie-gem5-pairs huggingface dataset:
// 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.694311116219086x):
#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 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: 5.209087487735539x):
#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<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.2359413353568085x):
#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;

#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.399993875470933x):
#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;

#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.341223306210659x):
#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;

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.274388549645427x):
#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;

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.272134361694132x):
#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;



#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;

}




// Faster C++ solution for the same problem (measured speedup: 5.363371207958762x):
#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 <math.h> 

#include <vector>

#include <algorithm>

#include <iomanip>      // std::setprecision

#include <map>

#include <unordered_map>

#include <string>

#include <set>



using namespace std;



int main()

{



	double N = 0;

	std::vector<int> nums;

	cin >> N;

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

	{

		int num;

		cin >> num;

		nums.push_back(num);

	}

	std::sort(nums.begin(), nums.end());

	int sol = 0;

	int i = 0, j = N-2, k = N-1;

	for (int k = N - 1; k > 1; --k)

	{

		for (int j = k - 1; j > 0; --j)

		{

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

			{

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

				{

					sol += j - i;

					break;

				}

			}

		}

	}

	std::cout << sol;

}


// Faster C++ solution for the same problem (measured speedup: 5.318601362552294x):
#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<vector>

#include<map>

#include<algorithm>

#include<cmath>

using namespace std;



int main()

{

    int N , ans = 0 ;

    cin >> N;

    vector<int>V(N);

    for (int j = 0; j < N; j++)

    {

        cin >> V[j];

    }

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

    int low = 0, high = 0, mid = 0;

    for (int j = 0; j < N-2; j++)

    {

        

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

        {



            low = i + 1;

            high = N-1;

            int temp = i;

            while (low <= high)

            {

                mid = (high + low) / 2;

                if (V[i] + V[j] > V[mid]) 

                {

                    temp = mid;

                    low = mid + 1;

                }

                else if (V[i] + V[j] <= V[mid]) { high = mid - 1; }

            }

            ans += (temp - i);

        }

    }



    cout << ans << endl;

}

// Faster C++ solution for the same problem (measured speedup: 5.226464277725074x):
#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 <vector>

using namespace std;

#define ll long long



int main() {

    ll n, triangle = 0;

    cin >> n;

    vector<ll> s(n);

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

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

    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(s[i] + s[j] > s[k] && s[i] + s[k] > s[j] && s[k] + s[j] > s[i]) {

                    triangle++;

                }

                else if (s[i] + s[j] <= s[k]) break;

            }

        }

    }

    cout << triangle << endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.2683130560173455x):
#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:
#define _USE_MATH_DEFIMES

#include <algorithm>

#include <array>

#include <bitset>

#include <cassert>

#include <cctype>

#include <climits>

#include <clocale>

#include <cmath>

#include <complex>

#include <cstdio>

#include <cstdlib>

#include <ctime>

#include <deque>

#include <fstream>

#include <functional>

#include <iomanip>

#include <iostream>

#include <iterator>

#include <list>

#include <map>

#include <numeric>

#include <queue>

#include <regex>

#include <set>

#include <sstream>

#include <stack>

#include <string>

#include <tuple>

#include <unordered_map>

#include <unordered_set>

#include <utility>

#include <vector>



const int MOD = 1'000'000'007;

const int INF = 1'000'000'000; //1e9

const int NIL = -1;

const long long LINF = 1'000'000'000'000'000'000; // 1e18

const long double EPS = 1E-10;



template<class T, class S> inline bool chmax(T &a, const S &b){

    if(a < b){

        a = b; return true;

    }

    return false;

}

template<class T, class S> inline bool chmin(T &a, const S &b){

    if(b < a){

        a = b; return true;

    }

    return false;

}

















int main(){

    int N; std::cin >> N;

    long long cnt(0);

    std::vector<int> L(N);

    for(int i(0); i < N; ++i) std::cin >> L[i];

    std::sort(std::begin(L), std::end(L));

    for(int mid(1), mid_len(N-1); mid < mid_len; ++mid){

        for(int high(mid+1); high < N; ++high){

            int lowlow(L[high] - L[mid] + 1);

            cnt += std::max(0L, std::distance(std::lower_bound(std::begin(L), std::end(L), lowlow), std::begin(L) + mid));

        }

    }

    std::cout << cnt << std::endl;

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.268377815841152x):
#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;

#define LL long long

#define sigma_size 30

#define max_size (int)(2e5+10)

#define MAX (int)(1e5+7)

int qread()

{

	char c; int s=0,t=1; while ((c=getchar())<'0' || c>'9') (c=='-' && (t=-1));

	do s=s*10+c-'0'; while ((c=getchar())>='0' && c<='9'); return s*t;

}



int L[2005];

int main ()

{

	int n = qread();

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

		cin >> L[i];

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

	int cnt = 0;

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

	{

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

		{

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

			int tot = lower_bound( L+1 , L+n+1 , d ) - L -1 ;

			cnt += tot-j;

			if ( d == L[tot] )	cnt--;

		}

	}

	cout << cnt << endl;

}

// Faster C++ solution for the same problem (measured speedup: 5.193797308276476x):
#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;

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: 1.1056433465923055x):
#include<bits/stdc++.h>

#define ll long long 

#define MAXN 200010

using namespace std;



int n,m;

int X[2010];



int main(){

	scanf("%d",&n);

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

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

	}

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

	

	ll ans=0;

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

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

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

		//	if(x>n)continue;

			ans+=x-1-j;

		}

	}

	printf("%lld",ans);

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

using namespace std;

int p(int a,int b,int c){

        if(a+b>c&&a+c>b&&b+c>a){

            return 1;

        }

    return 0;

}

    

int main(){

    int n,a[100001];

    cin>>n;

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

        cin>>a[i];

    }

    int ans=0;

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

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

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

            int it=lower_bound(a+1, a+n+1, a[i]+a[j])-a-2;

            if(it-j+1>0){

                ans+=it-j+1;

            }

        }

    }

    cout<<ans;

    return 0;

}


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

#include<string.h>

#include<algorithm>

using namespace std;

int n,ans;

int a[2005]; 

int main(){

	scanf("%d",&n);

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

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

//	int d=unique(a+1,a+n+1)-a-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])ans++;

	else break;

//	if(ans==0) puts("No triangles can be formed."); 

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

	return 0;

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

using namespace std;

int p(int a,int b,int c){

        if(a+b>c&&a+c>b&&b+c>a){

            return 1;

        }

    return 0;

}

    

int main(){

    int n,a[100001];

    cin>>n;

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

        cin>>a[i];

    }

    int ans=0;

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

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

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

            int it=lower_bound(a+1, a+n+1, a[i]+a[j])-a-2;

            if(it-j+1>0){

                ans+=it-j+1;

            }

        }

    }

    cout<<ans;

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.023815967944337x):
#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++;

				else break;

			}

		}

	}

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

}