#P6522. [CEOI 2010] tower (day2)

[CEOI 2010] tower (day2)

Description

The tower has a total of nn levels, and each level consists of one cubic stone block with side length aia_i. A block ii can be placed directly on top of block jj if and only if aiaj+Da_i \leq a_j + D, where DD is a given constant.

You need to find how many different building plans there are if all blocks are used. Output the result mod 109+9\bmod\ 10^9+9.

Note: Even if two blocks have the same side length, they are still considered different blocks.

Input Format

The first line contains two integers n,Dn, D.

The second line contains nn integers a1,,ana_1, \dots, a_n, representing the side lengths of the cubic stone blocks.

Output Format

Output one line with one integer, the total number of plans mod 109+9\bmod\ 10^9+9.

4 1
1 2 3 100
4
6 9
10 20 20 10 10 20
36

Hint

Sample Explanation

Sample 1 Explanation

First, place the block with side length 100100 at the bottom. The remaining blocks can be placed in any order except for the following two cases: 2,1,3 and 1,3,2.

Sample 2 Explanation

First, it is not allowed to place 2020 on top of 1010.

So, put all the 2020 blocks as a stack at the bottom, and all the 1010 blocks as a stack on the top.

That is (3!)×(3!)=36(3!)\times (3!) = 36.

Constraints

  • For 10%10\% of the testdata, n10n \le 10 is guaranteed;
  • For 30%30\% of the testdata, the number of plans does not exceed 10610^6;
  • For 45%45\% of the testdata, n20n \le 20 is guaranteed;
  • For 70%70\% of the testdata, n70n \le 70 is guaranteed;
  • For 100%100\% of the testdata, 2n6.2×1052 \le n \le 6.2 \times 10^5, and all numbers in the input are positive integers not exceeding 10910^9.

Notes

This problem is translated from CEOI 2010 day 2 T3 tower.

The translation copyright belongs to the problem provider

https://www.luogu.com.cn/user/45475

Translated by ChatGPT 5