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 rep(i, n) for(int(i) = 0; i < (int)(n); (i)++)
typedef long long ll;

int bitCount(unsigned int bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555); //  2bitごとに計算
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333); //  4bitごとに計算
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f); //  8bitごとに計算
    bits =
        (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff); //  16ビットごとに計算
    return (bits & 0x0000ffff) + (bits >> 16); //  32ビット分を計算
}

void func_A() {
    int A, B;
    cin >> A >> B;
    int res = A > 2 * B ? A - 2 * B : 0;
    cout << res << endl;
}
void func_B() {
    int N;
    cin >> N;
    vector<ll> d(N);
    rep(i, N) {
        cin >> d[i];
    }
    ll res = 0;
    for(int i = 0; i < N - 1; i++) {
        for(int j = i + 1; j < N; j++) {
            res += d[i] * d[j];
        }
    }
    cout << res << endl;
}
void func_C() {
    int N;
    string S, res;
    cin >> N;
    cin >> S;
    char now = S[0];
    rep(i, N) {
        if(now != S[i]) {
            res += now;
            now = S[i];
        }
    }
    if(res[res.size() - 1] != S[N - 1]) res += S[N - 1];
    cout << res.size() << endl;
}
void func_D() {
    unsigned int N;
    cin >> N;
    int res = 0;
    int *L = new int[N];
    rep(i, N) {
        cin >> L[i];
    }

    int l[3] = {0};
    for(int bit = 0; bit < (1 << N); ++bit) {
        if(bitCount(bit) == 3) {
            int cnt = 0;

            for(int i = 0; i < N; ++i) {
                if(bit & (1 << i)) { // i が bit に入るかどうか
                    l[cnt++] = L[i];
                }
                if(cnt == 3) {
                    break;
                }
            }
            if((l[0] < l[1] + l[2]) && (l[1] < l[0] + l[2]) &&
               (l[2] < l[1] + l[0])) {
                res++;
            }
        }
    }
    cout << res << endl;
    free(L);
}
int main() {
    func_D();
    return 0;
}