Language: C++

{.optimization:speed, checks:off.}
#{{{ header
import algorithm, sequtils, tables, macros, math, sets, strutils, streams
when defined(MYDEBUG):
  import header

proc scanf(formatstr: cstring){.header: "<stdio.h>", varargs.}
proc getchar(): char {.header: "<stdio.h>", varargs.}
proc nextInt(base:int = 0): int =
  scanf("%lld",addr result)
  result -= base
proc nextFloat(): float = scanf("%lf",addr result)
proc nextString(): string =
  var get = false;result = ""
  while true:
    var c = getchar()
    if int(c) > int(' '): get = true;result.add(c)
    elif get: break
template `max=`*(x,y:typed):void = x = max(x,y)
template `min=`*(x,y:typed):void = x = min(x,y)
template infty(T): untyped = ((T(1) shl T(sizeof(T)*8-2)) - 1)
#}}}

#{{{ gcd and inverse
const GCD_H = 0

proc gcd(a,b:int):int=
  if b == 0: return a
  else: return gcd(b,a mod b)
proc lcm(a,b:int):int=
  return a div gcd(a, b) * b
# a x + b y = gcd(a, b)
proc extgcd(a,b:int, x,y:var int):int =
  var
    g = a
  x = 1
  y = 0
  if b != 0:
    g = extgcd(b, a mod b, y, x)
    y -= (a div b) * x
  return g;

proc invMod(a,m:int):int =
  var
    x,y:int
  if extgcd(a, m, x, y) == 1: return (x + m) mod m
  else: return 0 # unsolvable
#}}}

let MOD = 1000000007

#{{{ Mint
type Mint = object
  v:int
proc newMint[T](a:T):Mint =
  var a = a
  a = a mod MOD
  if a < 0: a += MOD
  return Mint(v:a)
proc newMint(a:Mint):Mint =
  return a
proc `+=`[T](a:var Mint, b:T):void =
  a.v += newMint(b).v
  if a.v >= MOD:
    a.v -= MOD
proc `+`[T](a:Mint,b:T):Mint =
  var c = a
  c += b
  return c
proc `*=`[T](a:var Mint,b:T):void =
  a.v *= newMint(b).v
  a.v = a.v mod MOD
proc `*`[T](a:Mint,b:T):Mint =
  var c = a
  c *= b
  return c
proc `-`(a:Mint):Mint =
  if a.v == 0: return a
  else: return Mint(v:MOD - a.v)
proc `-=`[T](a:var Mint,b:T):void =
  a.v -= newMint(b).v
  if a.v < 0:
    a.v += MOD
proc `-`[T](a:Mint,b:T):Mint =
  var c = a
  c -= b
  return c
proc `$`(a:Mint):string =
  return $(a.v)
when declared(GCD_H):
  proc `/=`[T](a:var Mint,b:T):void =
    a.v *= invMod(newMint(b).v,MOD)
    a.v = a.v mod MOD
  proc `/`[T](a:Mint,b:T):Mint =
    var c = a
    c /= b
    return c
#}}}


#{{{ fact, comb, perm
var
  factorial_val = @[newMint(1)]
  inv_factorial_val = @[newMint(1)]
  comb_val = @[@[newMint(1)]]

proc fact(n:int):Mint =
  for i in len(factorial_val)..n:
    factorial_val.add(factorial_val[i-1] * i)
  return factorial_val[n]
proc inv_fact(n:int):Mint =
  for i in len(inv_factorial_val)..n:
    inv_factorial_val.add(newMint(1)/fact(i))
  return inv_factorial_val[n]

proc comb_memo(n,r:int):Mint =
  if n<0 or r<0 or n<r:
    return newMint(0)
  while comb_val.len < n + 1:
    var t = comb_val.len
    comb_val.add(newSeqWith(t + 1, newMint(0)))
    comb_val[t][0] = newMint(1)
    comb_val[t][t] = newMint(1)
    for i in 1..t-1:
      comb_val[t][i] = comb_val[t-1][i-1] + comb_val[t-1][i]
  return comb_val[n][r]

when declared(GCD_H):
  proc comb(n,r:int):Mint =
    if n<0 or r<0 or n<r:
      return newMint(0)
    else:
#      return fact(n)/(fact(r)*fact(n-r))
      return fact(n)*inv_fact(r)*inv_fact(n-r)
  proc perm(n,r:int):Mint =
    if n<0 or n<r:
      return newMint(0)
    else:
      return fact(n)/fact(n-r)
#}}}



proc solve(N:int, K:int) =
  if K == 1:
    echo 1
    return
  var dp = newSeqWith(2010,newSeqWith(2010,newMint(0)))
  dp[0][0] = newMint(1)
  let K1 = K - 1
  for a in 0..N:
    var d = N * K - a - 1
    for b in 0..a:
      # zero
      dp[a+1][b] += dp[a][b]
      # non-zero
#      if b < N: dp[a][b+1] += dp[a][b] * comb(N*K - a - (K - 1) * b - 1,K - 2) * (N - b)
      dp[a][b+1] += dp[a][b] * comb(d,K - 2) * (N - b)
      d -= K1
  echo dp[N][N]
  return

#{{{ main function
proc main() =
  var N = 0
  N = nextInt()
  var K = 0
  K = nextInt()
  solve(N, K);
  return

main()
#}}}

Compiler output:
a.cc:2:2: error: invalid preprocessing directive #{
    2 | #{{{ header
      |  ^
a.cc:19:10: error: stray '`' in program
   19 | template `max=`*(x,y:typed):void = x = max(x,y)
      |          ^
a.cc:19:15: error: stray '`' in program
   19 | template `max=`*(x,y:typed):void = x = max(x,y)
      |               ^
a.cc:20:10: error: stray '`' in program
   20 | template `min=`*(x,y:typed):void = x = min(x,y)
      |          ^
a.cc:20:15: error: stray '`' in program
   20 | template `min=`*(x,y:typed):void = x = min(x,y)
      |               ^
a.cc:22:2: error: invalid preprocessing directive #}
   22 | #}}}
      |  ^
a.cc:24:2: error: invalid preprocessing directive #{
   24 | #{{{ gcd and inverse
      |  ^
a.cc:32:3: error: invalid preprocessing directive #a
   32 | # a x + b y = gcd(a, b)
      |   ^
a.cc:47:18: error: stray '#' in program
   47 |   else: return 0 # unsolvable
      |                  ^
a.cc:48:2: error: invalid preprocessing directive #}
   48 | #}}}
      |  ^
a.cc:52:2: error: invalid preprocessing directive #{
   52 | #{{{ Mint
      |  ^
a.cc:62:6: error: stray '`' in program
   62 | proc `+=`[T](a:var Mint, b:T):void =
      |      ^
a.cc:62:9: error: stray '`' in program
   62 | proc `+=`[T](a:var Mint, b:T):void =
      |         ^
a.cc:66:6: error: stray '`' in program
   66 | proc `+`[T](a:Mint,b:T):Mint =
      |      ^
a.cc:66:8: error: stray '`' in program
   66 | proc `+`[T](a:Mint,b:T):Mint =
      |        ^
a.cc:70:6: error: stray '`' in program
   70 | proc `*=`[T](a:var Mint,b:T):void =
      |      ^
a.cc:70:9: error: stray '`' in program
   70 | proc `*=`[T](a:var Mint,b:T):void =
      |         ^
a.cc:73:6: error: stray '`' in program
   73 | proc `*`[T](a:Mint,b:T):Mint =
      |      ^
a.cc:73:8: error: stray '`' in program
   73 | proc `*`[T](a:Mint,b:T):Mint =
      |        ^
a.cc:77:6: error: stray '`' in program
   77 | proc `-`(a:Mint):Mint =
      |      ^
a.cc:77:8: error: stray '`' in program
   77 | proc `-`(a:Mint):Mint =
      |        ^
a.cc:80:6: error: stray '`' in program
   80 | proc `-=`[T](a:var Mint,b:T):void =
      |      ^
a.cc:80:9: error: stray '`' in program
   80 | proc `-=`[T](a:var Mint,b:T):void =
      |         ^
a.cc:84:6: error: stray '`' in program
   84 | proc `-`[T](a:Mint,b:T):Mint =
      |      ^
a.cc:84:8: error: stray '`' in program
   84 | proc `-`[T](a:Mint,b:T):Mint =
      |        ^
a.cc:88:6: error: stray '`' in program
   88 | proc `$`(a:Mint):string =
      |      ^
a.cc:88:8: error: stray '`' in program
   88 | proc `$`(a:Mint):string =
      |        ^
a.cc:91:8: error: stray '`' in program
   91 |   proc `/=`[T](a:var Mint,b:T):void =
      |        ^
a.cc:91:11: error: stray '`' in program
   91 |   proc `/=`[T](a:var Mint,b:T):void =
      |           ^
a.cc:94:8: error: stray '`' in program
   94 |   proc `/`[T](a:Mint,b:T):Mint =
      |        ^
a.cc:94:10: error: stray '`' in program
   94 |   proc `/`[T](a:Mint,b:T):Mint =
      |          ^
a.cc:98:2: error: invalid preprocessing directive #}
   98 | #}}}
      |  ^
a.cc:101:2: error: invalid preprocessing directive #{
  101 | #{{{ fact, comb, perm
      |  ^
a.cc:103:19: error: stray '@' in program
  103 |   factorial_val = @[newMint(1)]
      |                   ^
a.cc:104:23: error: stray '@' in program
  104 |   inv_factorial_val = @[newMint(1)]
      |                       ^
a.cc:105:14: error: stray '@' in program
  105 |   comb_val = @[@[newMint(1)]]
      |              ^
a.cc:105:16: error: stray '@' in program
  105 |   comb_val = @[@[newMint(1)]]
      |                ^
a.cc:124:14: error: too many decimal points in number
  124 |     for i in 1..t-1:
      |              ^~~~
a.cc:133:8: error: invalid preprocessing directive #return
  133 | #      return fact(n)/(fact(r)*fact(n-r))
      |        ^~~~~~
a.cc:140:2: error: invalid preprocessing directive #}
  140 | #}}}
      |  ^
a.cc:151:12: error: too many decimal points in number
  151 |   for a in 0..N:
      |            ^~~~
a.cc:153:14: error: too many decimal points in number
  153 |     for b in 0..a:
      |              ^~~~
a.cc:154:9: error: invalid preprocessing directive #zero
  154 |       # zero
      |         ^~~~
a.cc:156:9: error: invalid preprocessing directive #non
  156 |       # non-zero
      |         ^~~
a.cc:157:16: error:  ':' without preceding '?'
  157 | #      if b < N: dp[a][b+1] += dp[a][b] * comb(N*K - a - (K - 1) * b - 1,K - 2) * (N - b)
      |                ^
a.cc:157: error: unterminated #if
  157 | #      if b < N: dp[a][b+1] += dp[a][b] * comb(N*K - a - (K - 1) * b - 1,K - 2) * (N - b)
a.cc:1:1: error: expected unqualified-id before '{' token
    1 | {.optimization:speed, checks:off.}
      | ^
a.cc:3:1: error: 'import' does not name a type
    3 | import algorithm, sequtils, tables, macros, math, sets, strutils, streams
      | ^~~~~~
a.cc:3:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:8:1: error: 'proc' does not name a type
    8 | proc getchar(): char {.header: "<stdio.h>", varargs.}
      | ^~~~
a.cc:9:1: error: 'proc' does not name a type
    9 | proc nextInt(base:int = 0): int =
      | ^~~~
a.cc:14:19: error: 'result' does not name a type
   14 |   var get = false;result = ""
      |                   ^~~~~~
a.cc:17:38: error: 'result' does not name a type
   17 |     if int(c) > int(' '): get = true;result.add(c)
      |                                      ^~~~~~
a.cc:43:1: error: 'proc' does not name a type
   43 | proc invMod(a,m:int):int =
      | ^~~~