#K12066. Maximum Equilateral Triangles from Sticks
Maximum Equilateral Triangles from Sticks
Maximum Equilateral Triangles from Sticks
You are given N sticks, each with a specified length. Your task is to determine the maximum number of equilateral triangles that can be formed using these sticks. An equilateral triangle can be formed if and only if you have three sticks of the same length.
Note: You cannot break a stick, and each stick can be used in at most one triangle.
Mathematical Representation:
Given a multiset of stick lengths, if for a particular length l the frequency is f(l), then the number of triangles that can be formed from sticks of length l is \(\lfloor \frac{f(l)}{3} \rfloor\). The final answer is the sum of these values for all distinct stick lengths.
inputFormat
The first line of input contains an integer N, the number of sticks. The second line contains N space-separated integers representing the lengths of the sticks.
outputFormat
Output a single integer representing the maximum number of equilateral triangles that can be formed.## sample
8
3 3 3 3 3 3 3 3
2
</p>