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: Wrong Answer)

//Be Name Khoda
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using ordered_multiset =  tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long int LL;
typedef LL ll;
typedef long double ld;
typedef string str;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef stringstream strs;
 
#define X first
#define Y second
#define PB push_back
#define For(i,a,b) for (int i=a;i<b;i++)
#define Ford(i,a,b) for (int i=a;i>=b;i--)
#define smax(a,b) a=max(a,b)
#define smin(a,b) a=min(a,b)
#define SZ(a) ((ll)a.size())
#define ER(a) cout << #a << ' ' << a << endl
#define LB(a,n,x) (lower_bound(a,(a)+(n),x)-(a))
#define RET(x) { cout << x; exit(0); } 
const ll M=2e3+5,LG=32,SM=600+5,inf=1e18+5;
ll mod=1e9+7;
 
ll n,k;
ll dp[M][M];
ll fac[M*M],faci[M*M];

ll pwr(ll x,ll n)
{
    ll z=x,res=1;
    For(i,0,LG)
    {
        if ((n>>i)&1)
            res=(res*z)%mod;
        z=(z*z)%mod;
    }
    return res;
}

ll com(ll i,ll j)
{
    if (j>i) return 0;
    ll res=(fac[i]*faci[j])%mod;
    res=(res*faci[i-j])%mod;
    return res;
}

int main()
{
    cin >> n >> k;
    if (k==1) RET(1);
    fac[0]=1;
    faci[0]=1;
    For(i,1,n*k)
    {
        fac[i]=(fac[i-1]*i)%mod;
        faci[i]=pwr(fac[i],mod-2);
    }
    dp[1][0]=dp[1][1]=1;
    For(i,2,n+1)
    {
        //ER(i);
        dp[i][0]=com(i*(k-1)-1,k-2);
        //ER(dp[i][0]);
        For(j,1,i)
        {
            dp[i][j]=dp[i][j-1];
            dp[i][j]+=
                (com(i*(k-1)+j-1,k-2)
                *dp[i-1][j])%
                mod;
            dp[i][j]%=mod;            
        }
        dp[i][i]=dp[i][i-1];
    }
    RET((dp[n][n]*fac[n])%mod);
}