PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#TP0000058. Đếm tam giác từ những thanh gỗ (Triangles)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

2 lộ trình

Đếm tam giác từ những thanh gỗ (Triangles)

Triangles

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

Takahashi owns nn distinguishable sticks, numbered from 11 to nn. Stick ii has length LiL_i. 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 a,b,ca,b,c, all three strict inequalities a<b+ca<b+c, b<c+ab<c+a, and c<a+bc<a+b 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 nn: the number of sticks.
  • The second line contains exactly nn integers L1,…,LnL_1,\ldots,L_n: the stick lengths.

Output

Print one integer: the number of triples of distinct sticks forming a triangle.

Subtasks

  • Subtask 1 (20 points): 3≤n≤123\le n\le 12; 1≤Li≤10001\le L_i\le1000 for every ii; sticks are distinguished by their indices.
  • Subtask 2 (30 points): 3≤n≤1203\le n\le 120; 1≤Li≤10001\le L_i\le1000 for every ii; sticks are distinguished by their indices.
  • Subtask 3 (50 points): 3≤n≤20003\le n\le 2000; 1≤Li≤10001\le L_i\le1000 for every ii; sticks are distinguished by their indices.

Examples

Input

4
3 4 2 1

Output

1

Explanation

The lengths are 3,4,2,13,4,2,1. Among the (43)=4\binom{4}{3}=4 triples, only lengths {2,3,4}\{2,3,4\} satisfy the triangle inequality: 2+3>42+3>4. Each other triple has the sum of its two shorter sides at most its longest side. Thus the answer is 11.