Problem:
Score : 400 points

Problem Statement

Takahashi has N sticks that are distinguishable from each other. The length of the i-th stick is L_i.

He is going to form a triangle using three of these sticks. Let a, b, and c be the lengths of the three sticks used. Here, all of the following conditions must be satisfied:

a < b + c

b < c + a

c < a + b

How many different triangles can be formed? Two triangles are considered different when there is a stick used in only one of them.

Constraints

All values in input are integers.

3 \leq N \leq 2 \times 10^3

1 \leq L_i \leq 10^3

Input

Input is given from Standard Input in the following format:

N
L_1 L_2 ... L_N

Constraints

Print the number of different triangles that can be formed.

Sample Input 1

4
3 4 2 1

Sample Output 1

1

Only one triangle can be formed: the triangle formed by the first, second, and third sticks.

Sample Input 2

3
1 1000 1

Sample Output 2

0

No triangles can be formed.

Sample Input 3

7
218 786 704 233 645 728 389

Sample Output 3

23

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(ll i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
typedef tuple<ll,ll,ll> Tu;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807/5;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[8]={0,1,0,-1,1,1,-1,-1},mdy[8]={-1,0,1,0,1,-1,1,-1};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll n;
ll l[2010]={};
ll sum[2010]={};
ll ans=0;
int main(){
	cin>>n;
	REP(i,n){
		ll k;
		cin>>k;
		l[k]++;
	}
	for(ll i=1;i<2010;i++){
		sum[i]=sum[i-1]+l[i];
	}
	
	for(ll i=1;i<1001;i++){
		for(ll j=i+1;j<1001;j++){
			if(l[i]==0||l[j]==0)continue;
			ll t=i+j;
			ans+=(ll)(sum[t-1]-sum[j]);
			//cout<<i<<" "<<j<<" "<<ans<<endl;
			//cout<<sum[t-1]<<" "<<sum[j]<<endl;
		}
	}
	//cout<<ans<<endl;
	for(ll i=1;i<1001;i++){
		if(l[i]<2)continue;
		ll t=2*i;
		ans+=(ll)(sum[t-1]-l[i])*(l[i]*(l[i]-1)/2);
	}
	//cout<<ans<<endl;
	/*for(ll i=1;i<1001;i++){
		if(l[i]<3)continue;
		ll t=l[i]*(l[i]-1)*(l[i]-2)/6;
		//cout<<t<<endl;
		ans+=(ll)t;
	}*/
	cout<<ans<<endl;
	return 0;
}