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# (.NET Core 3.1.201) (judge verdict: Wrong Answer)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    class Program
    {
        static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }

        static long[] ReadLongs()
        {
            return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }

        static double ReadDouble()
        {
            return double.Parse(Console.ReadLine());
        }

        static double[] ReadDoubles()
        {
            return Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
        }

        static string ReadString()
        {
            return Console.ReadLine();
        }

        static string[] ReadStringSplit()
        {
            return Console.ReadLine().Split(' ');
        }

        static void A()
        {
            var AB = ReadLongs();
            var A = AB[0];
            var B = AB[1];
            Console.WriteLine(Math.Max(A - (2 * B), 0));
        }

        static void B()
        {
            var N = ReadLong();
            var ds = ReadLongs();
            long ans = 0;
            foreach (var x in Enumerable.Range(0, (int)N))
            {
                foreach (var y in Enumerable.Range(x, (int)N - x))
                {
                    if (x == y)
                    {
                        continue;
                    }
                    ans += ds[x] * ds[y];
                }
            }
            Console.WriteLine(ans);
        }

        static void C()
        {
            var N = ReadLong();
            var S = ReadString();
            char prev = '0';
            long ans = 0;
            foreach (var x in S)
            {
                if (x == prev)
                {
                    continue;
                }

                prev = x;
                ans++;
            }
            Console.WriteLine(ans);
        }

        static void D()
        {
            var N = ReadLongs();
            var LsI = ReadLongs();
            var Ls = LsI.ToList().OrderBy(x => x).ToList();
            long ans = 0;
            foreach (var a in Enumerable.Range(0, Ls.Count))
            {
                foreach (var b in Enumerable.Range(a + 1, Ls.Count - a))
                {
                    foreach (var c in Enumerable.Range(b + 1, Ls.Count - b))
                    {
                        if (a + b > c)
                        {
                            ans++;
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
            Console.WriteLine(ans);
        }

        static void Main(string[] args)
        {
            //A();
            //B();
            //C();
            D();
        }
    }
}