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: Accepted)

//https://atcoder.jp/contests/abc143/tasks/abc143_d
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define FOR(i,a,b) for(int64_t i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
void recursive_comb(vector<ll>& indexes, ll s, ll rest, std::function<void(vector<ll>&)> f) {
    if (rest == 0) {
        f(indexes);
    } else {
        if (s < 0) return;
        recursive_comb(indexes, s - 1, rest, f);
        indexes.at(rest - 1) = s;
        recursive_comb(indexes, s - 1, rest - 1, f);
    }
}
// nCkの組み合わせに対して処理を実行する
void foreach_comb(ll n, ll k, std::function<void(vector<ll>&)> f) {
    vector<ll> indexes(k);
    recursive_comb(indexes, n - 1, k, f);
}
//foreach_comb(N-1, 2, [&](vector<ll>& indexes) {
//    dump(indexes[0],indexes[1]);
//}
int main() {
#if LOCAL&01
    std::ifstream in("./test/sample-2.in"); //input.txt
    std::cin.rdbuf(in.rdbuf());
#else
    cin.tie(0);
    ios::sync_with_stdio(false);
#endif
    ll N; cin>>N;
    vector<ll> ln(N);
    for(auto&& l:ln){
        cin>>l;
    }
    sort(ln.begin(),ln.end());
    ll ans=0;
    REP(i,N){
        ll a=ln.at(i);
        FOR(j,i+1,N){
            //if(i==j)continue;
            ll b=ln.at(j);
            auto it = lower_bound(ln.begin(),ln.end(),a+b);
            //if (it==ln.end()) continue;
            if (it==ln.begin()) continue;
            --it;
            auto d = std::distance(ln.begin(),it);
            ans += max<ll>(d - j,0);
        }
    }
    cout<<ans<<endl;
    return 0;
#if 0
    //TLE...
    ll ans=0;
    foreach_comb(N,3,[&](vector<ll>& t){
        //dump(t);
        ll a=ln.at(t.at(0));
        ll b=ln.at(t.at(1));        
        ll c=ln.at(t.at(2));        
        if(a<b+c&&b<c+a&&c<a+b){
            ++ans;
        }
    });
    cout<<ans<<endl;
#endif
    return 0;
}