PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#TP0000057. Tòa tháp khổng lồ (A Huge Tower)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Tòa tháp khổng lồ (A Huge Tower)

A Huge Tower

Source: CEOI

Version: Phuoc Hung OJ Extended

Problem Statement

The Babylonians wish to build a tower by stacking all nn cubic blocks. Every block is a distinct physical object, even if two blocks have equal side lengths. Block ii has side length aia_i.

Blocks are stacked from bottom to top. If block AA is immediately above block BB, the side length of AA must not exceed the side length of BB plus DD: aA≤aB+Da_A\le a_B+D.

Count all valid orders of the blocks using every block exactly once. Two orders are different whenever the physical blocks occupy different positions. Output the answer modulo 109+910^9+9.

Input

  • The first line contains two positive integers n,Dn,D: the number of blocks and allowed tolerance.
  • The second line contains exactly nn positive integers a1,…,ana_1,\ldots,a_n, the block side lengths.

Output

Print one integer: the number of valid tower orders modulo 109+910^9+9.

Subtasks

  • Subtask 1 (20 points): 2≤n≤82\le n\le 8; 1≤D≤1091\le D\le10^9; 1≤ai≤1091\le a_i\le10^9 for all 1≤i≤n1\le i\le n; all blocks are distinct even when side lengths are equal.
  • Subtask 2 (30 points): 2≤n≤702\le n\le 70; 1≤D≤1091\le D\le10^9; 1≤ai≤1091\le a_i\le10^9 for all 1≤i≤n1\le i\le n; all blocks are distinct even when side lengths are equal.
  • Subtask 3 (50 points): 2≤n≤6200002\le n\le 620000; 1≤D≤1091\le D\le10^9; 1≤ai≤1091\le a_i\le10^9 for all 1≤i≤n1\le i\le n; all blocks are distinct even when side lengths are equal.

Examples

Input

4 1
1 2 3 100

Output

4

Explanation

There are four blocks of lengths 1,2,3,1001,2,3,100 with D=1D=1. The size-100100 block must be the bottommost block. Among the six orders of the remaining three blocks, exactly four respect the tolerance between every adjacent pair; the other two put size 33 directly above size 11. Therefore the answer is 44.