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

//BadWaper gg
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#define inf 1e9
#define eps 1e-6
#define mp make_pair
#define N 2010
#define M 4000010
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline ll read()
{
	char ch=getchar();
	ll s=0,w=1;
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
	return s*w;
}
int f[N][N];
int fac[M],inv[M];
int n,k;
const int mod=1e9+7;
inline int C(int n,int m){if(n<m)return 0;return 1LL*fac[n]*inv[m]%mod*inv[n-m]%mod;}
inline int Z(int x){return x>=mod?x-mod:x;}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	n=read(),k=read();
	if(k==1){printf("1\n");return 0;}
	fac[0]=1;
	for(register int i=1;i<=n*k;i++)fac[i]=1LL*fac[i-1]*i%mod;
	inv[0]=inv[1]=1;
	for(register int i=2;i<=n*k;i++)inv[i]=1LL*(mod-mod/i)*inv[mod%i]%mod;
	for(register int i=2;i<=n*k;i++)inv[i]=1LL*inv[i]*inv[i-1]%mod;
	f[0][0]=1;
	for(register int i=1;i<=n;i++)
	{
		f[i][0]=1;
		for(register int j=1;j<=i;j++)
		{
			f[i][j]=f[i-1][j];
			f[i][j]=Z(f[i][j]+1LL*f[i][j-1]*(n-j+1)%mod*C(n*k-(j-1)*(k-1)-i-1,k-2)%mod);
		}
	}
	printf("%d\n",f[n][n]);
	return 0;
}