This page is still under construction.

Parts of this page are still being built. What you see may change.

Hyper Checkers Score Counting

Interview

Time limit1sMemory limit512 MB

Summary
Count distinct ordered triples (a,b,c) drawn from n given cards such that max(a,b,c) <= k * min(a,b,c).
Level

Medium6 of 10

Topics
Sorting, Two pointers, Math, Combinatorics
Solved
No attempts yet

Problem

Andrey works as a judge at a hyper checkers championship. Each game of hyper checkers involves three players. During the game each player earns a positive integer score. If after the game the first player has aa points, the second has bb points, and the third has cc points, the game is said to have ended with the score a:b:ca:b:c.

Andrey knows that the rules of hyper checkers are set up so that in the result of a game the scores of any two players differ by no more than a factor of kk.

After a match, Andrey displays its result by placing three cards with the players' scores on a special board. For this he has a set of nn cards with the numbers x1,x2,…,xnx_1, x_2, \ldots, x_n written on them. To find out how ready he is for the championship, Andrey wants to know how many distinct score options he can display on the board using the cards he has.

Given the number kk and the numbers on the cards Andrey has, write a program that determines the number of distinct score options Andrey can display on the board.

Input

The first line of the input file contains two integers: nn and kk (3≤n≤100 0003 \le n \le 100\,000, 1≤k≤1091 \le k \le 10^9).

The second line of the input file contains nn integers x1,x2,…,xnx_1, x_2, \ldots, x_n (1≤xi≤1091 \le x_i \le 10^9).

Output

The output file must contain one integer: the number of distinct score options sought.

Hint

In the given example Andrey can display the following score options: 1:1:2, 1:2:1, 2:1:1, 1:2:2, 2:1:2, 2:2:1, 2:2:3, 2:3:2, 3:2:2. Other triples of numbers that can be formed using the available cards do not satisfy the condition that the scores of any two players differ by no more than a factor of k=2k = 2.

Examples1

  1. Example 1

    Input
    5 2
    1 1 2 2 3
    
    Expected output
    9