#P11951. Triangle Formation

    ID: 14060 Type: Default 1000ms 256MiB

Triangle Formation

Triangle Formation

You are given n sticks with lengths \(a_1, a_2, \ldots, a_n\). Determine the number of ways to choose three distinct sticks such that they can form a triangle.

A triangle can be formed from three sticks if and only if the sum of the lengths of the two shorter sticks is greater than the length of the longest stick. In mathematical terms, if we sort the three chosen sticks so that \(a \le b \le c\), then a triangle is possible if and only if \(a + b > c\).

inputFormat

The first line contains an integer \(n\) (\(3 \le n \le 10^5\)), the number of sticks.

The second line contains \(n\) integers \(a_1, a_2, \ldots, a_n\) (each \(1 \le a_i \le 10^9\)) representing the lengths of the sticks.

outputFormat

Output a single integer representing the number of ways to choose three sticks that can form a triangle.

sample

4
3 4 5 6
4