Count the number of triangles Given a list of positive integers, find the number of triangles we can form such that their side lengths are represented by three distinct entries of the input list.
(Inspiration comes from CR.)
Details

A triangle can be formed if all permutations of the three side lengths \$a,b,c\$ satisfy the strict triangle inequality $$a + b &gt; c.$$ (This means \$a+b &gt; c\$, \$a+c&gt;b\$ and \$b+c&gt;a\$ must all hold.)
The three side lengths \$a,b,c\$ must appear at distinct positions in the list, but do not necessarily have to be pairwise distinct.
The order of the three numbers in the input list does not matter. If we consider a list a and the three numbers a[i], a[j], a[k] (where i,j,k are pairwise different), then (a[i],a[j],a[k]), (a[i],a[k],a[j]), (a[j], a[i], a[k]) etc. all are considered as the same triangle.
The input list can assumed to contain at least 3 entries.
You can assume that the input list is sorted in ascending order.

Examples
A small test program can be found here on Try it online!
Input, Output:
[1,2,3]  0
[1,1,1]  1
[1,1,1,1] 4
[1,2,3,4] 1
[3,4,5,7] 3
[1,42,69,666,1000000] 0
[12,23,34,45,56,67,78,89] 34
[1,2,3,4,5,6,7,8,9,10] 50

For the input of [1,2,3,...,n-1,n] this is A002623.
For the input of [1,1,...,1] (length n) this is A000292.
For the input of the first n Fibonacci numbers (A000045) this is A000004.
R, 62 52 40 34 bytes



sum(c(1,1,-1)%*%combn(scan(),3)&gt;0)


Try it online!

Port of Luis Mendo's Octave solution

Since a&lt;=b&lt;=c, the triangle condition is equivalent to a+b-c&gt;0. The a+b-c is succinctly captured by the matrix product [1,1,-1] * X, where X is the 3-combinations of the input array.

There were a lot of suggestions for improvements made by 3 different people in the comments:


Robert S. for suggesting scan.
Robin Ryder for suggesting improvements to the triangle inequality and this odd one which requires the input to be in descending order (which just goes to show how important a flexible input format is).
and finally Nick Kennedy for the following:


R, 40 bytes



y=combn(scan(),3);sum(y[3,]&lt;y[1,]+y[2,])


Try it online!