Geometric Triplets
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 numbers and a ratio , you need to count all triplets with such that the sequence elements satisfy
Input Format
- The first line contains two space-separated integers: , the number of elements in the sequence, and , the common ratio.
- The second line contains space-separated integers denoting the elements of the sequence: .
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
Code Editor
Submit a solution. Authentication is required to create submissions.