Geometric Triplets

Time limit: 2 secMemory limit: 256 MBData Structures, Math, Dynamic Programming

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 nn numbers and a ratio rr, you need to count all triplets (i,j,k)(i, j, k) with i<j<ki < j < k such that the sequence elements satisfy

aj=ai×randak=aj×r.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: nn, the number of elements in the sequence, and rr, the common ratio.
  • The second line contains nn space-separated integers denoting the elements of the sequence: a1,a2,,ana_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

Code Editor

Submit a solution. Authentication is required to create submissions.

Language
Theme
Source code is submitted to the judge for testing.