#P9197. Permutation with Bounded Sum of Absolute Differences

    ID: 22352 Type: Default 1000ms 256MiB

Permutation with Bounded Sum of Absolute Differences

Permutation with Bounded Sum of Absolute Differences

You are given N distinct integers \(A_1, A_2, \ldots, A_N\). Your task is to count the number of permutations \(f_1, f_2, \ldots, f_N\) of these integers such that

[ |f_1 - f_2| + |f_2 - f_3| + \cdots + |f_{N-1} - f_N| \le L, ]

Since the answer can be large, output it modulo \(10^9+7\).

Note: A permutation is an arrangement of all given numbers in some order. Ensure that the sum of absolute differences between consecutive numbers in the permutation does not exceed L.

inputFormat

The input consists of two lines. The first line contains two integers N and L, where N is the number of integers and L is the upper bound for the sum of differences. The second line contains N distinct integers \(A_1, A_2, \ldots, A_N\) separated by spaces.

outputFormat

Output a single integer: the number of valid permutations modulo \(10^9+7\).

sample

3 3
1 3 6
0

</p>