Vera invented a new sorting algorithm. She wrote the Python function below to count how many steps her algorithm takes.
def steps(array):
if len(array) == 0:
return 0
pivot = array[0]
count = 0
lesser = []
greater = []
for element in array:
count += 1
if element < pivot:
lesser.append(element)
elif element > pivot:
greater.append(element)
return count + steps(lesser) + steps(greater)
A permutation P of size N is an ordered sequence of integers P1,P2,…,PN whose N entries are distinct positive integers, each of them at most N.
You are given integers N and K. Count the permutations P of size N for which steps(P) returns K. The count can be large, so print it modulo 109+7.