LogiQuest

442. Valid Triangle Number

MediumTwo PointersSorting

Count the triples of positions whose values can be the side lengths of a triangle (each pair sums to more than the third).

Input format

Line 1: n Line 2: n non-negative integers

Output format

The count.

Example 1

Input

4
2 2 3 4

Output

3

Example 2

Input

4
4 2 3 4

Output

4

Constraints

1 ≤ n ≤ 1000

Read input from standard input and print the answer to standard output. Your code is judged against 5 test cases, most of them hidden.

Loading the MyLoginn IDE…