Number of good trees

Count labeled trees on kn nodes split into n blocks of size k, with no edge inside a block, modulo 1e9+7.

Hard8CombinatoricsMathMatrixNumber theoryNo attempts yetTime limit2sMemory limit512 MB

Problem

A good tree is a tree that satisfies both of these conditions.

  • It has k×nk \times n nodes, numbered from 00 to k×n1k \times n - 1.
  • Nodes ii and jj with 0i,j<k×n0 \le i, j < k \times n and i/k=j/ki / k = j / k are not adjacent. Here // is integer division, so 7/2=37 / 2 = 3.

The second condition says that if you cut the numbers into nn blocks of kk consecutive values, no edge joins two nodes of the same block. Any other pair of nodes may be joined by an edge.

The nodes are labelled, so two trees with different edge sets count as different trees.

Given nn and kk, write a program that counts the good trees.

Input

The first line contains nn (1n1051 \le n \le 10^5) and kk (1k31 \le k \le 3), separated by a space.

Output

Print the number of good trees modulo 109+710^9 + 7.