Cubes

아직 제출이 없습니다시간 제한1초메모리 제한1024 MB

문제

Among her toys, Octavia has NN cubes of identical size. The cubes might differ in weight, but it is also possible for two cubes to have the same weight. Octavia enjoys setting her cubes in a long sequence and after many hours playing with them, she started wondering about the number of different sequences of cubes that can be obtained.

The sequence of cubes is represented by NN integers, where each one corresponds to the weight of the corresponding cube in the initial sequence. Octavia can pick two adjacent cubes and swap them only if their total weight is not larger than the integer KK. Octavia may repeat the operation of swapping any two adjacent cubes with total weight not larger than KK infinitely many times. Two sequences are considered different if their corresponding sequences of cube weights are different.

Let us take as an example the following case with 44 cubes with weights \[1,2,1,3]\[1, 2, 1, 3] and K=3K = 3. There are 33 possible cube sequences that can be obtained. The first of those is the initial sequence. To obtain the second sequence, we can swap cubes at positions 22 and 33 from the initial sequence to obtain the sequence: \[1,1,2,3]\[1, 1, 2, 3]. Note that we cannot swap cubes at positions 11 and 33 in the initial sequence, because they are not adjacent. We also cannot swap the cubes at positions 33 and 44, because their total weight is 44, which is larger than K=3K = 3. We can obtain the last sequence by swapping the first two cubes in the initial sequence and obtain \[2,1,1,3]\[2, 1, 1, 3]. Note that if we start with the initial sequence and K=1K = 1, there is just one possible sequence; when K=2K = 2, there is just one sequence as well; if K=4K = 4, there are 66 sequences; when K=5K = 5, there are 1212 sequences.

Write a program cubes, which helps Octavia find the number of different sequences of cubes.

입력

There are 22 integers on the first line: NN - the number of cubes and KK - the maximum total weight of two adjacent cubes that can be swapped. There will be NN positive integers w_1,,w_Nw\_1, \dots , w\_N, on the second line of the input, corresponding to the weights in the initial sequence.

출력

A single line with the number of possible sequences that Octavia can obtain, modulo 1,000,000,0071\\,000\\,000\\,007.

제한

  • 1N300,0001 ≤ N ≤ 300\\,000
  • 1w_i,K1,000,000,0001 ≤ w\_i , K ≤ 1\\,000\\,000\\,000

힌트

Example №1: In problem statement.

Example №2: We can only swap the cubes with weights 11 and 33, so the answer is 22, and the two possible sequences are \[4,3,1,5,2]\[4, 3, 1, 5, 2] and \[4,1,3,5,2]\[4, 1, 3, 5, 2].