stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;



typedef long long ll;

typedef double dd;

typedef vector<int> vi;

typedef vector<ll> vl;

typedef pair<int,int> pii;



const int mx=1e6+11;

const double PI = acos(-1);

#define MOD 1000000007





#define nl '\n'

#define pb push_back

#define F first

#define S second

#define I insert

#define mp make_pair



#define sz(x) x.size()

#define tt int t; cin>>t; while(t--)

#define lo(i,a,b) for(int i=a;i<b;i++)

#define be(a) (a).begin(),(a).end()

#define rbe(a) (a).rbegin(),(a).rend()

#define mem(a,b) memset(a,b,sizeof(a))



#define su ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

#define frac cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);



#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

void faltu () {            cerr << endl;}

template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}





int main()

{

   su;

   int a,b;

   cin>>a>>b;

   if(b%a)

    cout<<b-a<<nl;

   else

    cout<<a+b<<nl;

   return 0;

}


// Optimized solution to the same problem (faster):
#include <stdio.h>



int main() {

	int A,B;

	scanf("%d%d",&A,&B);

	if(B%A==0){

		printf("%d",B+A);

		

	}else{

		printf("%d",B-A);

	}

	return 0;

}



	 

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

#define LL long long

#define db double



using namespace std;

const int N=2000+10,mod=1e9+7;

int rd()

{

    int x=0,w=1;char ch=0;

    while(ch<'0'||ch>'9'){if(ch=='-') w=-1;ch=getchar();}

    while(ch>='0'&&ch<='9'){x=x*10+(ch^48);ch=getchar();}

    return x*w;

}

void ad(int &x,int y){x+=y,x-=x>=mod?mod:0;}

int fpow(int a,int b){int an=1;while(b){if(b&1) an=1ll*an*a%mod;a=1ll*a*a%mod,b>>=1;}return an;}

int ginv(int a){return fpow(a,mod-2);}

int n,k,fac[N*N],iac[N*N],f[2][N];

int C(int a,int b){return b<0||a<b?0:1ll*fac[a]*iac[b]%mod*iac[a-b]%mod;}



int main()

{

	n=rd(),k=rd();

	if(k==1){puts("1");exit(0);}

	fac[0]=1;

	for(int i=1;i<=n*k;++i) fac[i]=1ll*fac[i-1]*i%mod;

	iac[n*k]=ginv(fac[n*k]);

	for(int i=n*k;i;--i) iac[i-1]=1ll*iac[i]*i%mod;

	int nw=1,la=0;

	f[la][0]=1;

	for(int i=1;i<=n+n;++i)

	{

		for(int j=0;j<i&&j<=n;++j)

		{

			if(!f[la][j]) continue;

			if(j<=n) ad(f[nw][j+1],1ll*f[la][j]*C(i-1+(k-2)*(j+1),k-2)%mod);

			if(j>=i-j) ad(f[nw][j],f[la][j]);

			f[la][j]=0;

		}

		nw^=1,la^=1;

	}

	printf("%d\n",(int)(1ll*fac[n]*f[la][n]%mod));

	return 0;

}


// Optimized solution to the same problem (faster):
#include <stdio.h>

#include <algorithm>

#include <memory.h>



typedef long long ll;



const ll N = 2e3 + 5;

const ll P = 1e9 + 7;



ll n, k;

ll fac[N * N];

ll f[N][N];



ll read()

{

    ll x = 0, f = 1;

    char ch = getchar();

    while ('0' > ch or ch > '9')

        f = ch == '-' ? -1 : 1, ch = getchar();

    while ('0' <= ch and ch <= '9')

        x = x * 10 + ch - 48, ch = getchar();

    return x * f;

}



ll pow(ll x, ll k)

{

    ll res = 1;

    for (x %= P; k; k >>= 1, x = x * x % P)

        if (k & 1)

            res = res * x % P;

    return res;

}



ll C(ll n, ll m) { return ((fac[n] * pow(fac[m], P - 2)) % P * pow(fac[n - m], P - 2) % P); }



signed main()

{

    n = read(), k = read();

    if (k == 1)

    {

        puts("1");

        return 0;

    }

    fac[0] = 1;

    for (ll i = 1; i <= n * k; i++)

        fac[i] = fac[i - 1] * i % P;

    for (ll i = 0; i <= n; i++)

        f[i][0] = 1;

    for (ll i = 1; i <= n; i++)

        for (ll j = 1; j <= i; j++)

            f[i][j] = f[i - 1][j] +

                      f[i][j - 1] * (n - j + 1) % P *

                          C(n * k - i - (j - 1) * (k - 1) - 1, k - 2) % P;

    printf("%lld", f[n][n]);

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define ll long long

const int md=1e9+7;

const int maxm=4001000;

const int maxn=2001;

int read(){

	int x=0,flag=1;char ch=getchar();

	while(!isdigit(ch)&&ch!='-') ch=getchar();

	if (ch=='-') flag=-1,ch=getchar();

	while(isdigit(ch)) x=(x<<3)+(x<<1)+(ch-'0'),ch=getchar();

	return x*flag;

}

ll fac[maxm],inv[maxm];

ll ksm(ll a,ll b){

	ll res=1;

	while(b){

		if (b&1) res=res*a%md;

		a=a*a%md;b>>=1;

	}

	return res;

}

void init(int n){

	fac[0]=1;

	for (int i=1;i<=n;++i)

		fac[i]=fac[i-1]*i%md;

	inv[n]=ksm(fac[n],md-2);

	for (int i=n;i;--i)

		inv[i-1]=inv[i]*i%md;

}

ll c(int n,int m){

	return fac[n]*inv[m]%md*inv[n-m]%md;

}

int n,k,f[maxn][maxn];

int main(){

	n=read(),k=read();

	if (k==1) return puts("1"),0;

	init(n*k);

	f[0][0]=1;

	for (int i=1;i<=n;++i){

		for (int j=0;j<=i;++j){

			f[i][j]=f[i-1][j];

			if (!j) continue;

			(f[i][j]+=1ll*f[i][j-1]*(n-j+1)%md*

			c(n-i+(n-j+1)*(k-1)-1,k-2)%md)%=md;

		}

	}

	printf("%d\n",f[n][n]);

}

// Optimized solution to the same problem (faster):
#include <algorithm>

#include <cmath>

#include <cstdio>

#include <cstring>



const int N = 2e3 + 32, M = 5e6 + 65, P = 1e9 + 7;



int pw(int x, int y) {

	int r = 1;

	for (; y; y >>= 1, x = 1ll * x * x % P)

		if (y & 1) r = 1ll * r * x % P;

	return r;

}



int fac[M], ifac[M];

int c(int n, int m) { return 1ll * n[fac] * m[ifac] % P * (n - m)[ifac] % P; }



int n, k, dp[N][N];

int main() {

	scanf("%d%d", &n, &k);

	if (k == 1) return puts("1"), 0;

	0 [fac] = 0 [ifac] = 1;

	for (int i = 1; i <= n * k; i++) i[fac] = 1ll * (i - 1)[fac] * i % P;

	(n * k)[ifac] = pw((n * k)[fac], P - 2);

	for (int i = n * k - 1; i >= 1; i--) i[ifac] = 1ll * (i + 1)[ifac] * (i + 1) % P;

	for (int i = 0; i <= n; i++)

		for (int j = 0; j <= i; j++)

			if (i || j)

				dp[i][j] = (dp[i - 1][j] +

							(n - j + 1ll) * c(n * k - i - (j - 1) * (k - 1) - 1, k - 2) %

								P * dp[i][j - 1]) %

						   P;

			else

				dp[0][0] = 1;

	printf("%d", dp[n][n]);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<cstdio>

#include<cmath>

#include<cstring>

#include<algorithm>

#include<queue>

#include<vector>

#define pb push_back

#define mp make_pair

#define fi first

#define se second

using namespace std;



typedef long long LL;



inline int read()

{

	char c=getchar();int num=0,f=1;

	for(;!isdigit(c);c=getchar())

		f=c=='-'?-1:f;

	for(;isdigit(c);c=getchar())

		num=num*10+c-'0';

	return num*f;

}



const int N=2e3+5;

const int M=N*N;

const int mod=1e9+7;



inline void add(int &x,int y){(x+=y)>=mod?x-=mod:0;}



int ksm(int x,int k)

{

	int res=1;

	for(;k;k>>=1,x=1ll*x*x%mod)

		if(k&1) res=1ll*res*x%mod;

	return res;

}



int n,k;

int f[N][N],fac[M],ifac[M];



int C(int n,int m){return 1ll*fac[n]*ifac[m]%mod*ifac[n-m]%mod;}



int main()

{

	n=read(),k=read();

	if(k==1)

	{

		cout<<1;

		return 0;

	}

	fac[0]=1;

	for(int i=1;i<=n*k;++i) fac[i]=1ll*fac[i-1]*i%mod;

	ifac[n*k]=ksm(fac[n*k],mod-2);

	for(int i=n*k-1;~i;--i) ifac[i]=1ll*ifac[i+1]*(i+1)%mod;

	f[0][0]=1;

	for(int i=0;i<=n;++i)

	{

		for(int j=0;j<=i;++j)

		{

			if(i) add(f[i][j],f[i-1][j]);

			if(j) add(f[i][j],1ll*f[i][j-1]*C(n-i+(n-j+1)*(k-1)-1,k-2)%mod);

		}

	}

	cout<<1ll*f[n][n]*fac[n]%mod;

	return 0;

}

// Optimized solution to the same problem (faster):
#include <algorithm>

#include <cmath>

#include <cstdio>

#include <cstring>



const int N = 2e3 + 32, M = 5e6 + 65, P = 1e9 + 7;



int pw(int x, int y) {

	int r = 1;

	for (; y; y >>= 1, x = 1ll * x * x % P)

		if (y & 1) r = 1ll * r * x % P;

	return r;

}



int fac[M], ifac[M];

int c(int n, int m) { return 1ll * n[fac] * m[ifac] % P * (n - m)[ifac] % P; }



int n, k, dp[N][N];

int main() {

	scanf("%d%d", &n, &k);

	if (k == 1) return puts("1"), 0;

	0 [fac] = 0 [ifac] = 1;

	for (int i = 1; i <= n * k; i++) i[fac] = 1ll * (i - 1)[fac] * i % P;

	(n * k)[ifac] = pw((n * k)[fac], P - 2);

	for (int i = n * k - 1; i >= 1; i--) i[ifac] = 1ll * (i + 1)[ifac] * (i + 1) % P;

	for (int i = 0; i <= n; i++)

		for (int j = 0; j <= i; j++)

			if (i || j)

				dp[i][j] = (dp[i - 1][j] +

							(n - j + 1ll) * c(n * k - i - (j - 1) * (k - 1) - 1, k - 2) %

								P * dp[i][j - 1]) %

						   P;

			else

				dp[0][0] = 1;

	printf("%d", dp[n][n]);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <cstdio>

using namespace std;



const int MOD(1000000007);

int n, k;

int fac[4000000], inv_fac[4000000], dp[2001];





int Power(long long a, int b)

{

	long long ret(1ll);

	

	while (b) {

		b & 1 && (ret *= a);

		ret >= MOD && (ret %= MOD);

		a *= a;

		a >= MOD && (a %= MOD);

		b >>= 1;

	}

	return ret;

}





int main()

{

	register long long lt;

	int t;

	

	scanf("%d%d", &n, &k);

	if (k == 1) {

		printf("1\n");

		return 0;

	}

	fac[0] = 1;

	t = n * k;

	for (int i = 1; i < t; ++i) {

		lt = (long long)i * fac[i - 1];

		fac[i] = lt < MOD ? lt : lt % MOD; 

	}

	inv_fac[t - 1] = Power((long long)fac[t - 1], MOD - 2);

	for (int i = t - 2; i; --i) {

		lt = (long long)(i + 1) * inv_fac[i + 1];

		inv_fac[i] = lt < MOD ? lt : lt % MOD;

	}

	inv_fac[0] = 1;

	dp[0] = 1;

	t = -2;

	for (int i = 1; i <= n; ++i) {

		t += k - 1;

		for (int j = 0; j <= i; ++j) {

			++t;

			lt = (long long)fac[t] * inv_fac[t - k + 2];

			lt >= MOD && (lt %= MOD);

			lt *= (long long)inv_fac[k - 2];

			lt >= MOD && (lt %= MOD);

			lt *= (long long)dp[j];

			j && (lt += dp[j - 1]);

			dp[j] = lt < MOD ? lt : lt % MOD;

		}

		t -= i + 1;

	}

	lt = (long long)dp[n] * fac[n] % MOD;

	printf("%lld\n", lt);

	return 0;

}




// Optimized solution to the same problem (faster):
#include <algorithm>

#include <cmath>

#include <cstdio>

#include <cstring>



const int N = 2e3 + 32, M = 5e6 + 65, P = 1e9 + 7;



int pw(int x, int y) {

	int r = 1;

	for (; y; y >>= 1, x = 1ll * x * x % P)

		if (y & 1) r = 1ll * r * x % P;

	return r;

}



int fac[M], ifac[M];

int c(int n, int m) { return 1ll * n[fac] * m[ifac] % P * (n - m)[ifac] % P; }



int n, k, dp[N][N];

int main() {

	scanf("%d%d", &n, &k);

	if (k == 1) return puts("1"), 0;

	0 [fac] = 0 [ifac] = 1;

	for (int i = 1; i <= n * k; i++) i[fac] = 1ll * (i - 1)[fac] * i % P;

	(n * k)[ifac] = pw((n * k)[fac], P - 2);

	for (int i = n * k - 1; i >= 1; i--) i[ifac] = 1ll * (i + 1)[ifac] * (i + 1) % P;

	for (int i = 0; i <= n; i++)

		for (int j = 0; j <= i; j++)

			if (i || j)

				dp[i][j] = (dp[i - 1][j] +

							(n - j + 1ll) * c(n * k - i - (j - 1) * (k - 1) - 1, k - 2) %

								P * dp[i][j - 1]) %

						   P;

			else

				dp[0][0] = 1;

	printf("%d", dp[n][n]);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define ll long long

using namespace std;

const ll P=1e9+7,MAXN=4e6+10;

ll n,k,fac[MAXN],inv[MAXN],dp[2010][2010];

ll qpow (ll a,ll b) {

	ll res=1;

	while (b) {

		if (b&1) {

			res=(res*a)%P;

		}

		a=(a*a)%P;

		b>>=1;

	}

	return res;

}

ll c (ll n,ll m) {

	return (((fac[n]*inv[m])%P)*inv[n-m])%P;

}

int main () {

	scanf("%lld%lld",&n,&k);

	if (k==1) {

		printf("%d\n",1);

		return 0;

	}

	fac[0]=inv[0]=1;

	for (ll i=1;i<=n*k;i++) {

		fac[i]=(i*fac[i-1])%P;

	}

	inv[n*k]=qpow(fac[n*k],P-2);

	for (ll i=n*k-1;i>=1;i--) {

		inv[i]=(inv[i+1]*(i+1))%P;

	}

	for (int i=1;i<=n;i++) {

		dp[i][0]=1;

	}

	for (int i=1;i<=n;i++) {

		for (int j=1;j<=i;j++) {

			dp[i][j]=(dp[i-1][j]+(((dp[i][j-1]*(n-j+1))%P)*c(n*k-i-1-(j-1)*(k-1),k-2))%P)%P;

		}

	}

	printf("%lld\n",dp[n][n]);

	return 0;

}

// Optimized solution to the same problem (faster):
#include <algorithm>

#include <cmath>

#include <cstdio>

#include <cstring>



const int N = 2e3 + 32, M = 5e6 + 65, P = 1e9 + 7;



int pw(int x, int y) {

	int r = 1;

	for (; y; y >>= 1, x = 1ll * x * x % P)

		if (y & 1) r = 1ll * r * x % P;

	return r;

}



int fac[M], ifac[M];

int c(int n, int m) { return 1ll * n[fac] * m[ifac] % P * (n - m)[ifac] % P; }



int n, k, dp[N][N];

int main() {

	scanf("%d%d", &n, &k);

	if (k == 1) return puts("1"), 0;

	0 [fac] = 0 [ifac] = 1;

	for (int i = 1; i <= n * k; i++) i[fac] = 1ll * (i - 1)[fac] * i % P;

	(n * k)[ifac] = pw((n * k)[fac], P - 2);

	for (int i = n * k - 1; i >= 1; i--) i[ifac] = 1ll * (i + 1)[ifac] * (i + 1) % P;

	for (int i = 0; i <= n; i++)

		for (int j = 0; j <= i; j++)

			if (i || j)

				dp[i][j] = (dp[i - 1][j] +

							(n - j + 1ll) * c(n * k - i - (j - 1) * (k - 1) - 1, k - 2) %

								P * dp[i][j - 1]) %

						   P;

			else

				dp[0][0] = 1;

	printf("%d", dp[n][n]);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<iomanip>

#include<stack>

#include<queue>

#include<list>

#include<vector>

#include<set>

#include<map>

#include<string>

#include<algorithm>

#include<cmath>

#include<cstdio>

#include<cstring>

#include<cstdlib>

#include<ctime>

#define ll long long

#define ld double

#define inf 2001

#define infm inf*inf

#define mod ((ll)1e9+7)

#define INF (int)(1e9) 

#define pi acos(-1)

#define rd(n) {n=0;char ch;int f=0;do{ch=getchar();if(ch=='-'){f=1;}}while(ch<'0'||ch>'9');while('0'<=ch&&ch<='9'){n=(n<<1)+(n<<3)+ch-48;ch=getchar();}if(f)n=-n;}

using namespace std;



ll getinv(ll x){

	ll k=mod-2,ans=1;

	while (k){

		if (k&1){

			ans=ans*x%mod;

		}

		x=x*x%mod;

		k/=2;

	}

	return ans;

}



ll fact[infm],invf[infm];



void prework(int N){

	fact[0]=1;

	for (int i=1;i<=N;i++){

		fact[i]=fact[i-1]*i%mod;

	}

	invf[N]=getinv(fact[N]);

	for (int i=N-1;i>=0;i--){

		invf[i]=invf[i+1]*(i+1)%mod;

	}

	return;

}



ll C(int x,int y){

	return fact[x]*invf[y]%mod*invf[x-y]%mod;

}



ll cal(int x,int y){

	return C(x+y,x);

}



int n,K;

int f[inf][inf];



int main(){

	rd(n) rd(K)

	if (K==1){

		puts("1");

		return 0;

	}

	prework(n*K);

	f[0][0]=1;

	for (int i=1;i<=n;i++){

		ll sum=0;

		for (int j=i;j>=1;j--){

			sum=(sum+f[i-1][j-1])%mod;

			f[i][j]=sum*cal((i-1)*K-j+1,K-2)%mod;

		}

	}

	ll ans=0;

	for (int i=0;i<=n;i++){

		ans=(ans+f[n][i])%mod;

	}

	printf("%lld\n",ans*fact[n]%mod);

	return 0;

}




// Optimized solution to the same problem (faster):
#include <algorithm>

#include <cmath>

#include <cstdio>

#include <cstring>



const int N = 2e3 + 32, M = 5e6 + 65, P = 1e9 + 7;



int pw(int x, int y) {

	int r = 1;

	for (; y; y >>= 1, x = 1ll * x * x % P)

		if (y & 1) r = 1ll * r * x % P;

	return r;

}



int fac[M], ifac[M];

int c(int n, int m) { return 1ll * n[fac] * m[ifac] % P * (n - m)[ifac] % P; }



int n, k, dp[N][N];

int main() {

	scanf("%d%d", &n, &k);

	if (k == 1) return puts("1"), 0;

	0 [fac] = 0 [ifac] = 1;

	for (int i = 1; i <= n * k; i++) i[fac] = 1ll * (i - 1)[fac] * i % P;

	(n * k)[ifac] = pw((n * k)[fac], P - 2);

	for (int i = n * k - 1; i >= 1; i--) i[ifac] = 1ll * (i + 1)[ifac] * (i + 1) % P;

	for (int i = 0; i <= n; i++)

		for (int j = 0; j <= i; j++)

			if (i || j)

				dp[i][j] = (dp[i - 1][j] +

							(n - j + 1ll) * c(n * k - i - (j - 1) * (k - 1) - 1, k - 2) %

								P * dp[i][j - 1]) %

						   P;

			else

				dp[0][0] = 1;

	printf("%d", dp[n][n]);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define ll long long

using namespace std;

const int maxn=2000+10;

const int p=1e9+7;

int n,k,f[maxn][maxn],farc[maxn*maxn],inv[maxn*maxn];



int C(int n,int m){

	return (ll)farc[n]*inv[m]%p*(ll)inv[n-m]%p;

}



int main()

{

	scanf("%d%d",&n,&k);k--;

	if(!k){printf("1\n");return 0;}

	farc[0]=farc[1]=inv[0]=inv[1]=1;

	for(int i=2;i<=n*k+n+k;i++){

		farc[i]=(ll)farc[i-1]*i%p;

		inv[i]=(ll)(p-p/i)*inv[p%i]%p;

	}

	for(int i=2;i<=n*k+n+k;i++) inv[i]=(ll)inv[i]*inv[i-1]%p;

	f[0][0]=1;

	for(int i=0;i<=n;i++)

		for(int j=i;j<=n;j++){

			if(i>0) f[i][j]=(f[i][j]+f[i-1][j])%p;

			if(j>0) f[i][j]=(f[i][j]+(ll)f[i][j-1]*C(i+(j-1)*k+k-1,k-1)%p)%p;

		}

	printf("%d\n",(ll)f[n][n]*farc[n]%p);

	return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#define mo 1000000007

int fac[4000005],inv[4000005],n,k,f[2005][2005];

int C(int n,int m){return 1ll*fac[n]*inv[m]%mo*inv[n-m]%mo;}

int ksm(int a,int p)

{int ans=1;for(;p;p>>=1,a=1ll*a*a%mo)if(p&1)ans=1ll*ans*a%mo;return ans;}

int main()

{

	scanf("%d%d",&n,&k);

	if(k==1){printf("1\n");return 0;}

	f[0][0]=1;inv[0]=fac[0]=1;

	for(int i=1;i<=n*k;i++)fac[i]=fac[i-1]*1ll*i%mo;

	inv[n*k]=ksm(fac[n*k],mo-2);

	for(int i=n*k-1;i;i--)inv[i]=inv[i+1]*1ll*(i+1)%mo;

	for(int i=1;i<=n;i++)

	{

		f[i][0]=f[i-1][0];

	 	for(int j=1;j<=i;j++)

	  	 f[i][j]=(f[i-1][j]+f[i][j-1]*1ll*C(n*k-(j-1)*(k-1)-i-1,k-2)%mo)%mo;

	}printf("%d\n",f[n][n]*1ll*fac[n]%mo);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

#define LL long long

#define RG register

#define R RG int

using namespace std;

const LL N=2009,M=N*N,YL=1e9+7;

int f[N][N],fac[M],inv[M];

inline int fm(RG LL b){

	RG LL a=1;

	for(R k=YL-2;k;k>>=1,b=b*b%YL)

		if(k&1)a=a*b%YL;

	return a;

}

inline int C(R n,R m){

	if(n<0||m<0||n<m)return 0;

	return(LL)fac[n]*inv[m]%YL*inv[n-m]%YL;

}

int main(){

	R n,k,nk;

	scanf("%d%d",&n,&k);nk=n*k;

	if(k==1)return puts("1"),0;

	for(R i=fac[0]=1;i<=nk;++i)

		fac[i]=fac[i-1]*(LL)i%YL;

	inv[nk]=fm(fac[nk]);

	for(R i=nk;i;--i)

		inv[i-1]=inv[i]*(LL)i%YL;

	f[0][0]=1;

	for(R i=1;i<=n;++i)

		for(R j=f[i][0]=1;j<=i;++j)

			f[i][j]=(f[i-1][j]+(LL)f[i][j-1]*(n-j+1)%YL*C(n-i+(n-j+1)*(k-1)-1,k-2))%YL;

	printf("%d\n",f[n][n]);

	return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#define mo 1000000007

int fac[4000005],inv[4000005],n,k,f[2005][2005];

int C(int n,int m){return 1ll*fac[n]*inv[m]%mo*inv[n-m]%mo;}

int ksm(int a,int p)

{int ans=1;for(;p;p>>=1,a=1ll*a*a%mo)if(p&1)ans=1ll*ans*a%mo;return ans;}

int main()

{

	scanf("%d%d",&n,&k);

	if(k==1){printf("1\n");return 0;}

	f[0][0]=1;inv[0]=fac[0]=1;

	for(int i=1;i<=n*k;i++)fac[i]=fac[i-1]*1ll*i%mo;

	inv[n*k]=ksm(fac[n*k],mo-2);

	for(int i=n*k-1;i;i--)inv[i]=inv[i+1]*1ll*(i+1)%mo;

	for(int i=1;i<=n;i++)

	{

		f[i][0]=f[i-1][0];

	 	for(int j=1;j<=i;j++)

	  	 f[i][j]=(f[i-1][j]+f[i][j-1]*1ll*C(n*k-(j-1)*(k-1)-i-1,k-2)%mo)%mo;

	}printf("%d\n",f[n][n]*1ll*fac[n]%mo);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<algorithm>

#include<cstdio>

#include<cstring>

#define Mod 1000000007

using namespace std;

long long f[2010][2010];

int n,k;

long long fac[4000010],inv[4000010];

long long fpow(long long a,long long b)

{

	long long ans=1,t=a;

	while(b)

	{

		if(b&1)ans=ans*t%Mod;

		t=t*t%Mod;

		b>>=1;

	}

	return ans;

}

void getfac()

{

	fac[0]=1;

	for(int i=1;i<=n*k;i++)

		fac[i]=fac[i-1]*i%Mod;

	inv[n*k]=fpow(fac[n*k],Mod-2);

	for(int i=n*k;i;i--)

		inv[i-1]=inv[i]*i%Mod;

	return ;

}

long long C(int a,int b)

{

	return fac[a]*inv[b]%Mod*inv[a-b]%Mod;

}

int main()

{

	cin>>n>>k;

	if(k==1){

		cout<<1<<"\n";

		return 0;

	}

	getfac();

	f[0][0]=1;

	for(int i=1;i<=n;i++)

		for(int j=0;j<=i;j++)

		{

			f[i][j]+=f[i-1][j];

			if(j)

				f[i][j]=(f[i][j]+f[i][j-1]*(n-j+1)%Mod*C(n-i+(k-1)*(n-j+1)-1,k-2)%Mod)%Mod;

		}

	printf("%lld\n",f[n][n]);

	return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#define mo 1000000007

int fac[4000005],inv[4000005],n,k,f[2005][2005];

int C(int n,int m){return 1ll*fac[n]*inv[m]%mo*inv[n-m]%mo;}

int ksm(int a,int p)

{int ans=1;for(;p;p>>=1,a=1ll*a*a%mo)if(p&1)ans=1ll*ans*a%mo;return ans;}

int main()

{

	scanf("%d%d",&n,&k);

	if(k==1){printf("1\n");return 0;}

	f[0][0]=1;inv[0]=fac[0]=1;

	for(int i=1;i<=n*k;i++)fac[i]=fac[i-1]*1ll*i%mo;

	inv[n*k]=ksm(fac[n*k],mo-2);

	for(int i=n*k-1;i;i--)inv[i]=inv[i+1]*1ll*(i+1)%mo;

	for(int i=1;i<=n;i++)

	{

		f[i][0]=f[i-1][0];

	 	for(int j=1;j<=i;j++)

	  	 f[i][j]=(f[i-1][j]+f[i][j-1]*1ll*C(n*k-(j-1)*(k-1)-i-1,k-2)%mo)%mo;

	}printf("%d\n",f[n][n]*1ll*fac[n]%mo);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



typedef long long lint;

const int maxn = 2005, mod = 1e9 + 7;



int n, k, m, fac[maxn * maxn], ifac[maxn * maxn], f[maxn][maxn];



inline int gi()

{

	char c = getchar();

	while (c < '0' || c > '9') c = getchar();

	int sum = 0;

	while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();

	return sum;

}



inline void inc(int &a, int b) {a += b; if (a >= mod) a -= mod;}

inline int C(int n, int m)

{

	return (lint)fac[n] * ifac[m] % mod * ifac[n - m] % mod;

}



int main()

{

	n = gi(); k = gi();

	if (k == 1) return puts("1"), 0;



	m = n * k;

	fac[0] = ifac[0] = ifac[1] = 1;

	for (int i = 1; i <= m; ++i) fac[i] = (lint)fac[i - 1] * i % mod;

	for (int i = 2; i <= m; ++i) ifac[i] = (lint)(mod - mod / i) * ifac[mod % i] % mod;

	for (int i = 1; i <= m; ++i) ifac[i] = (lint)ifac[i - 1] * ifac[i] % mod;



	f[1][0] = 1;

	for (int i = 1; i <= n; ++i)

		for (int j = 0; j <= i; ++j) {

			if (i > j) inc(f[i][j], f[i - 1][j]);

			if (j) inc(f[i][j], (lint)f[i][j - 1] * C(m - i - (j - 1) * (k - 1) - 1, k - 2) % mod);

		}



	printf("%lld\n", (lint)f[n][n] * fac[n] % mod);

	

	return 0;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#define mo 1000000007

int fac[4000005],inv[4000005],n,k,f[2005][2005];

int C(int n,int m){return 1ll*fac[n]*inv[m]%mo*inv[n-m]%mo;}

int ksm(int a,int p)

{int ans=1;for(;p;p>>=1,a=1ll*a*a%mo)if(p&1)ans=1ll*ans*a%mo;return ans;}

int main()

{

	scanf("%d%d",&n,&k);

	if(k==1){printf("1\n");return 0;}

	f[0][0]=1;inv[0]=fac[0]=1;

	for(int i=1;i<=n*k;i++)fac[i]=fac[i-1]*1ll*i%mo;

	inv[n*k]=ksm(fac[n*k],mo-2);

	for(int i=n*k-1;i;i--)inv[i]=inv[i+1]*1ll*(i+1)%mo;

	for(int i=1;i<=n;i++)

	{

		f[i][0]=f[i-1][0];

	 	for(int j=1;j<=i;j++)

	  	 f[i][j]=(f[i-1][j]+f[i][j-1]*1ll*C(n*k-(j-1)*(k-1)-i-1,k-2)%mo)%mo;

	}printf("%d\n",f[n][n]*1ll*fac[n]%mo);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



#define ull unsigned long long



const int MaxN(2003);

const int MaxL(4000003);

const int Mod(1e9 + 7);



int F[MaxN][MaxN];

int fac[MaxL], rfac[MaxL];



int fexp(int x, int k)

{

	int res = 1;

	for(; k; k >>= 1, x = (ull) x * x % Mod)

		if(k & 1) res = (ull) res * x % Mod;

	return res;

}



inline int C(int n, int m)

{

	return n < m ? 0 : (ull) fac[n] * rfac[m] % Mod * rfac[n - m] % Mod;

}



int main()

{

	int n, K;

#ifdef zxp

	freopen("ball.in", "r", stdin);

	freopen("ball.out", "w", stdout);

#endif

	scanf("%d%d", &n, &K);

	if(K == 1) return puts("1"), 0;

	for(int i = fac[0] = 1; i <= n * K; i++)

		fac[i] = (ull) fac[i - 1] * i % Mod;

	rfac[n * K] = fexp(fac[n * K], Mod - 2);

	for(int i = n * K; i; i--)

		rfac[i - 1] = (ull) rfac[i] * i % Mod;

	F[0][0] = 1;

	for(int i = 1; i <= n; i++)

		for(int j = 0; j <= i; j++)

		{

			F[i][j] = F[i - 1][j];

			if(j) F[i][j] = (F[i][j] + (ull) (n - j + 1) * C((K - 1) * (n - j + 1) + n - i - 1, K - 2) % Mod * F[i][j - 1]) % Mod;

		}

	printf("%d\n", F[n][n]);

	return 0;

}


// Optimized solution to the same problem (faster):
#include <cstdio>

#include <algorithm>

using namespace std;

const int MAXN=2010;

const int MOD=1e9+7;

int n,k;

long long fac[MAXN*MAXN],inv[MAXN*MAXN],f[MAXN][MAXN];

long long C(long long x,long long y)

{

	return fac[x]*inv[y]%MOD*inv[x-y]%MOD;

}

long long qpow(long long x,long long y)

{

	long long tmp=1;

	for(;y;y>>=1,x=x*x%MOD)if(y&1)tmp=tmp*x%MOD;

	return tmp;

}

int main()

{

//	freopen("test.in","r",stdin);

//	freopen("test.out","w",stdout);

	scanf("%d%d",&n,&k);

	if(k==1)

	{

		printf("1");

		return 0;

	}

	fac[0]=1;

	for(int i=1;i<=n*k;i++)fac[i]=fac[i-1]*i%MOD;

	inv[n*k]=qpow(fac[n*k],MOD-2);

	for(int i=n*k;i>=1;i--)inv[i-1]=inv[i]*i%MOD;

	f[0][0]=1;

	for(int i=1;i<=n;i++)

		for(int j=0;j<=i;j++)

		{

			f[i][j]=f[i-1][j];

			if(!j)continue;

			f[i][j]=(f[i][j]+f[i][j-1]*(n-j+1)%MOD*C(n-i+(n-j+1)*(k-1)-1,k-2))%MOD;

		}

	printf("%lld\n",f[n][n]);

	return 0;

}

// Fastest known solution for this problem: