Problem:
Problem Statement

Snuke loves colorful balls. He has a total of N×K balls, K in each of his favorite N colors. The colors are numbered 1 through N.

He will arrange all of the balls in a row from left to right, in arbitrary order. Then, for each of the N colors, he will paint the leftmost ball of that color into color 0, a color different from any of the N original colors.

After painting, how many sequences of the colors of the balls are possible? Find this number modulo 10^9+7.

Constraints

1≤N,K≤2,000

Input

The input is given from Standard Input in the following format:

N K

Output

Print the number of the possible sequences of the colors of the balls after painting, modulo 10^9+7.

Sample Input 1

2 2

Sample Output 1

4

The following 4 sequences are possible:

(0,1,0,2)

(0,0,1,2)

(0,2,0,1)

(0,0,2,1)

Sample Input 2

3 1

Sample Output 2

1

The following 1 sequence is possible:

(0,0,0)

Sample Input 3

2 3

Sample Output 3

14

Sample Input 4

2000 2000

Sample Output 4

546381702

Solution in OCaml (4.02.3) (judge verdict: Accepted)

let modulo = 1000000007

let ( +% ) a b = let c = a + b in if c > modulo then c - modulo else c
let ( -% ) a b = if a >= b then a - b else modulo + a - b
let ( *% ) a b = a * b mod modulo

let pow k =
  let rec aux accu k = function
  | 0 -> accu
  | n when n mod 2 = 0 -> aux accu (k *% k) (n/2)
  | n -> aux (accu *% k) (k *% k) (n/2) in
  aux 1 k

let inv k = pow k (modulo-2)

let n, k = Scanf.scanf "%d %d" (fun x y -> x, y)

let () = if k = 1 then begin print_int 1; exit 0 end

let smax = n * k
let factbl = Array.make (smax+1) 1
let ifactbl = Array.make (smax+1) 0
let () = for i = 1 to smax do factbl.(i) <- factbl.(i-1) *% i done;
         ifactbl.(smax) <- inv factbl.(smax);
         for i = smax-1 downto 0 do ifactbl.(i) <- ifactbl.(i+1) *% (i+1) done

let binom n k = factbl.(n) *% ifactbl.(k) *% ifactbl.(n-k)


let dp = Array.make (n+1) 0

let () = dp.(0) <- 1;
         for i = 0 to n-1 do for j = i+1 to n do
           dp.(j) <- dp.(j) +% dp.(j-1) *% binom (i+j*(k-1)-1) (k-2) done done;
         print_int (factbl.(n) *% dp.(n))