Suppose we have two values n and m. We have to find number of possible arrangements of humble matrices of order n x m. A matrix is said to be humble when
If the answer is too large then return result mod 10^9 + 7.
So, if the input is like n = 2 m = 2, then the output will be 2, because there are two possible matrices -
To solve this, we will follow these steps −
Let us see the following implementation to get better understanding −
p = 10**9+7 def solve(n, m): result =  for x in range(2,10**6+1): temp = result[-1] temp = (temp*x) % p result.append(temp) if(m > n): temp = n n = m m = temp prod = 1 for x in range(1,m): prod = (prod * result[x-1]) % p prod = (prod**2) % p for x in range(n-m+1): prod = (prod*result[m-1]) % p return prod n = 3 m = 3 print(solve(n, m))