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 C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <bitset>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <cmath>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#ifdef WIN32
#define LLIO "%I64d"
#else
#define LLIO "%lld"
#endif

struct FastIO {
    inline FastIO& operator >> (int& x) {
        x = 0; char f = 0, ch = getchar();
        while(ch > '9' || ch < '0') f |= (ch == '-'), ch = getchar();
        while(ch <= '9' && ch >= '0') x = x * 10 + ch - 48, ch = getchar();
        return x = (f ? -x : x), *this;
    }
    inline FastIO& operator >> (long long& x) {
        x = 0; char f = 0, ch = getchar();
        while(ch > '9' || ch < '0') f |= (ch == '-'), ch = getchar();
        while(ch <= '9' && ch >= '0') x = x * 10 + ch - 48, ch = getchar();
        return x = (f ? -x : x), *this;
    }
    inline FastIO& operator >> (double& x) {
        x = 0; char f = 0, ch = getchar();
        double d = 0.1;
        while(ch > '9' || ch < '0') f |= (ch == '-'), ch = getchar();
        while(ch <= '9' && ch >= '0') x = x * 10 + ch - 48, ch = getchar();
        if(ch == '.') {
            ch = getchar();
            while(ch <= '9' && ch >= '0') x += d * (ch ^ 48), d *= 0.1, ch = getchar();
        }
        return x = (f ? -x : x), *this;
    }
}rin;
const int mod = 1e9 + 7;
ll f[2500][2500];
ll jc[10000007], inv[10000007];
ll ksm(ll x, int p) {
	ll ans = 1;
	while(p) {
		if(p & 1) ans = ans * x % mod;
		x = x * x % mod;
		p >>= 1;
	}
	return ans;
}
ll C(int n, int m) {
	if(m > n) return 0;
	return jc[n] * inv[m] % mod * inv[n - m] % mod;
}
int main() {
	jc[0] = inv[0] = 1;
	for(int i = 1 ; i <= 10000000 ; ++ i) jc[i] = jc[i - 1] * i % mod;
	inv[10000000] = ksm(jc[10000000], mod - 2);
	for(int i = 9999999 ; i >= 1 ; -- i) inv[i] = inv[i + 1] * (i + 1) % mod;
	int n, k; rin >> n >> k;
	if(k == 1) {puts("1"); return 0;}
	f[1][0] = 1;
	for(int i = 1 ; i <= n ; ++ i) {
		for(int j = 0 ; j <= i ; ++ j) {
			if(i > j) f[i][j] = f[i][j] + f[i - 1][j];
			if(j) f[i][j] = (f[i][j] + f[i][j - 1] * C(n * k - i - (j - 1) * (k - 1) - 1, k - 2) % mod) % mod;
		}
	}
	printf(LLIO "\n", f[n][n] * jc[n] % mod);
	return 0;
}