#P11556. Super Checkers Score Combinations
Super Checkers Score Combinations
Super Checkers Score Combinations
Andrey is the referee of a Super Checkers competition. In every match there are exactly three players, and in a match the players earn positive integer scores. If the first player scores \(a\) points, the second \(b\) points, and the third \(c\) points, then the match result is denoted as \(a\!:\!b\!:\!c\).
The rules require that for any two players the ratio of their scores is at most \(k\); that is, if \(m=\min\{a,b,c\}\) and \(M=\max\{a,b,c\}\), then \(\frac{M}{m}\le k\). After the match, Andrey displays the result by showing three score cards on a display.
Andrey owns \(n\) cards with numbers \(x_1, x_2, \dots, x_n\) written on them. Each card is distinct, even if some cards have the same number.
To test his preparation, Andrey wonders how many different ordered score combinations (i.e. arrangements of three distinct cards) he can display such that the scores satisfy the rule \(\frac{M}{m}\le k\). Note that since the cards are distinct, different orderings of the same triple of cards are considered different combinations.
Input and output format details are provided below.
inputFormat
The first line contains two integers \(n\) and \(k\) (with \(n\ge 3\)). The second line contains \(n\) positive integers \(x_1, x_2, \dots, x_n\) representing the numbers on the cards, separated by spaces.
outputFormat
Output a single integer, representing the total number of different ordered score combinations that can be displayed on the screen. In each valid combination, if the scores are \(a\), \(b\), and \(c\), then it must hold that \(\frac{\max\{a,b,c\}}{\min\{a,b,c\}}\le k\).
sample
4 2
1 1 2 3
6