NOTATRI  Not a Triangle
You have N (3 ≤ N ≤ 2,000) wooden sticks, which are labeled from 1 to N. The ith stick has a length of L_{i} (1 ≤ L_{i} ≤ 1,000,000). Your friend has challenged you to a simple game: you will pick three sticks at random, and if your friend can form a triangle with them (degenerate triangles included), he wins; otherwise, you win. You are not sure if your friend is trying to trick you, so you would like to determine your chances of winning by computing the number of ways you could choose three sticks (regardless of order) such that it is impossible to form a triangle with them.
Input
The input file consists of multiple test cases. Each test case starts with the single integer N, followed by a line with the integers L_{1}, ..., L_{N}. The input is terminated with N = 0, which should not be processed.
Output
For each test case, output a single line containing the number of triples.
Example
Input: 3 4 2 10 3 1 2 3 4 5 2 9 6 0 Output: 1 0 2
For the first test case, 4 + 2 < 10, so you will win with the one available triple. For the second case, 1 + 2 is equal to 3; since degenerate triangles are allowed, the answer is 0.
hide comments
stranger77:
20170820 09:00:00
sticks of equal length is considered different because of labelling from 1 to N 

suchith:
20170805 08:23:39
done with O(n^2*log(n)). good problems for beginners and there can be multiple sticks with same length


codiyapa420:
20170523 14:27:45
@lalwr nice fake alca :)


deep_1:
20170323 04:06:38
easy O(n^2*lg(n)) ..... AC in one go!!!!! 

nilabja16180:
20170322 12:43:14
There can be multiple stick of same length, got me a WA! 

da_201501181:
20170212 15:10:41
AC in one GO..!!


sarthakshah30:
20161230 14:32:24
O(n^2)


smtcoder:
20160903 14:25:48
my 50th.... :)


Anuj Arora:
20160821 12:49:31
Phew........lot of corner cases....nice binary search problem..........better to get a O(n^2) soln 

iharsh234:
20160816 21:30:08
O(n^2) best timed solution.

Added by:  Neal Wu 
Date:  20080803 
Time limit:  0.418s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All except: ERL JSRHINO 