#P6686. 混凝土数学
混凝土数学
Description
You are reading Concrete Mathematics when the construction site next to you starts working. You find watching their work more interesting, so you look out the window and notice some wooden sticks of different lengths. Specifically, you see sticks numbered , with lengths . A sudden idea comes to you: how many ways are there to take out sticks such that they can form an isosceles triangle? You do not want the output number to be too large, so the final count should be taken modulo .
The requirements for an isosceles triangle are: the sum of any two sides is greater than the third side, and at least two sides have equal length.
For example, if the stick lengths are , then you have ways. The chosen stick indices are: , , , , , .
Input Format
The first line contains a positive integer , representing the number of sticks.
The second line contains positive integers, representing .
Output Format
Output one number: the total number of valid ways modulo .
6
3 3 2 2 4 5
6
6
1 1 4 5 1 4
5
6
2 2 2 2 2 2
20
Hint
- Subtask 1 ( pts): .
- Subtask 2 ( pts): .
- Subtask 3 ( pts): All stick lengths are equal.
- Subtask 4 ( pts): No special constraints.
For of the testdata: , .
Translated by ChatGPT 5
京公网安备 11011102002149号