시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
1 초 | 512 MB | 15 | 12 | 12 | 80.000% |
Marichka has a lot of potato in her basement. There are n bags with potato in a line. The i-th of them contains ai potatoes.
Zenyk loves to shuffle those bags. During one shuffle operation he can grab two adjacent bags and swap their positions if the total number of potatoes in this two bags does not exceed number k. Zenyk can perform as many shuffle operations as he wishes.
Once Zenyk and Marichka wondered, what is the total number of bag permutations Zenyk can achieve. Two bag permutations are considered different if there is a position where two bags have different number of potatoes.
The first line contains two integers n (1 ≤ n ≤ 105) and k (0 ≤ k ≤ 2 · 109). The second line contains n integers ai (1 ≤ ai ≤ 109).
Single integer — the number of different permutations modulo 109 + 7.
3 7 5 2 4
3
5 4 1 2 3 2 1
10