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++ (Clang 10.0.0) (judge verdict: Accepted)

#include<cstdio>
#include<cctype>

#define maxn 2222
#define mod 1000000007

inline int read(){
	int r=0,f=0;
	char c;
	while(!isdigit(c=getchar()))f|=(c=='-');
	while(isdigit(c))r=(r<<1)+(r<<3)+(c^48),c=getchar();
	return f?-r:r;
}

inline long long qpow(long long a,int b){
	long long ans=1;
	for(;b;b>>=1){
		if(b&1)(ans*=a)%=mod;
		(a*=a)%=mod;
	}
	return ans;
}

int n,k;

long long frac[maxn*maxn],invf[maxn*maxn],f[maxn][maxn];

inline long long C(int n,int m){
	return frac[n]*invf[m]%mod*invf[n-m]%mod;
}

int main(){
	n=read(),k=read();
	if(k==1)return puts("1"),0;
	frac[0]=1;
	for(int i=1;i<=n*k;i++)
		frac[i]=frac[i-1]*i%mod;
	invf[n*k]=qpow(frac[n*k],mod-2);
	for(int i=n*k;i>=1;i--)
		invf[i-1]=invf[i]*i%mod;
	for(int i=1;i<=n;i++)f[i][0]=1;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=i;j++)
			f[i][j]=(f[i-1][j]+f[i][j-1]*(n-j+1)%mod*C(n*k-i-1-(j-1)*(k-1),k-2)%mod)%mod;
	printf("%lld\n",f[n][n]);
	return 0;
}