Geometric Triplets
Time limit: 2.0 sec
Memory limit: 256 MB
Problem Statement
In the ancient empire of Numenor, the royal mathematician has discovered a hidden pattern in the ancient scrolls. The scrolls contain a sequence of numbers, and it is believed that certain triplets of these numbers, when arranged in order, follow a mystical geometric progression. Your task is to help the mathematician count all the triplets in the sequence that form a geometric progression with a given common ratio.
More formally, given a sequence of $n$ numbers and a ratio $r$, you need to count all triplets $(i, j, k)$ with $i < j < k$ such that the sequence elements satisfy
$$ a_j = a_i \times r \quad \text{and} \quad a_k = a_j \times r. $$
## Input Format
- The first line contains two space-separated integers: $n$, the number of elements in the sequence, and $r$, the common ratio.
- The second line contains $n$ space-separated integers denoting the elements of the sequence: $a_1, a_2, \dots, a_n$.
## Output Format
Print a single integer representing the total number of triplets that form a geometric progression following the conditions mentioned above.
## Examples
#### Input
6 3
1 3 9 9 27 81
#### Output
6
#### Input
5 1
1 1 1 1 1
#### Output
10