Given a sequence of length
n and a positive integer
k, you can permute the sequence. The goal is to permute the sequence in such a way that the difference between any two adjacent elements is at least
k. How many different permutations can achieve this goal? It is guaranteed that the
n elements in the sequence are all distinct.
输入描述:
The first line contains two integers
n(1≤n≤8) and
k(1≤k≤20), representing the length of the sequence and the difference value, respectively.
The second line contains
n integers a1,a2,...,an(1≤ai≤20), representing the elements in the sequence.
输出描述:
Output an integer in a single line, representing the number of permutations that achieve the goal.
示例1
说明
In the example, only permutaions
[1,4,2] and
[2,4,1] achieve the goal.