NOTATRI - Not a Triangle


You have N (3 ≤ N ≤ 2,000) wooden sticks, which are labeled from 1 to N. The i-th stick has a length of Li (1 ≤ Li ≤ 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 L1, ..., LN. 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
shashi roshan: 2014-05-30 18:50:38

100th on spoj :) AC on naive solution ... O( n^2 * log2(n) ) ...

Last edit: 2014-05-30 18:51:19
SHIVAM DIXIT: 2014-04-28 12:59:21

O(n^2 * lgN) is accepted....

SHIVAM DIXIT: 2014-04-28 12:59:21

O(n^2 * lgN) is accepted....

No_words: 2014-01-11 11:43:16

Last edit: 2014-01-11 11:51:15
P_Quantum: 2013-12-27 07:40:55

Easy..!!

sobhan: 2013-10-31 17:32:46

easy one

Aniket Kumar: 2013-06-04 07:05:57

n^2lgN algo for tle..
for WA's try :
6
1 2 3 3 3 5
o/p
4

gourav: 2013-01-01 13:19:11

are wah!! new thing learnt today... today's job done with this qstn :-)

Darky: 2013-01-01 12:51:20

O(N^2lgN) passes. Nice question!


Added by:Neal Wu
Date:2008-08-03
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ERL JS-RHINO