#TP0000058. Đếm tam giác từ những thanh gỗ (Triangles)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đếm tam giác từ những thanh gỗ (Triangles)
Triangles
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Takahashi owns distinguishable sticks, numbered from to . Stick has length . Sticks of the same length are still different physical sticks.
Choose three distinct sticks as the sides of a nondegenerate triangle. If their lengths are , all three strict inequalities , , and must hold.
Two choices are different if their sets of chosen sticks differ, regardless of order. Count the triples that can form a triangle.
Input
- The first line contains integer : the number of sticks.
- The second line contains exactly integers : the stick lengths.
Output
Print one integer: the number of triples of distinct sticks forming a triangle.
Subtasks
- Subtask 1 (20 points): ; for every ; sticks are distinguished by their indices.
- Subtask 2 (30 points): ; for every ; sticks are distinguished by their indices.
- Subtask 3 (50 points): ; for every ; sticks are distinguished by their indices.
Examples
Input
4
3 4 2 1
Output
1
Explanation
The lengths are . Among the triples, only lengths satisfy the triangle inequality: . Each other triple has the sum of its two shorter sides at most its longest side. Thus the answer is .