Calculate the number of ways to place $n$ rooks on $n \times n$ chessboard so that both following conditions are met:

  each empty cell is under attack;  exactly $k$ pairs of rooks attack each other. 

An empty cell is under attack if there is at least one rook in the same row or at least one rook in the same column. Two rooks attack each other if they share the same row or column, and there are no other rooks between them. For example, there are only two pairs of rooks that attack each other in the following picture:

 [Image] One of the ways to place the rooks for $n = 3$ and $k = 2$ 

Two ways to place the rooks are considered different if there exists at least one cell which is empty in one of the ways but contains a rook in another way.

The answer might be large, so print it modulo $998244353$.


-----Input-----

The only line of the input contains two integers $n$ and $k$ ($1 \le n \le 200000$; $0 \le k \le \frac{n(n - 1)}{2}$).


-----Output-----

Print one integer — the number of ways to place the rooks, taken modulo $998244353$.


-----Examples-----
Input
3 2

Output
6

Input
3 3

Output
0

Input
4 0

Output
24

Input
1337 42

Output
807905441

Difficulty: HARD
Tags: Polynomials and generating functions

Combinatorics

Mathematics

Starter code:

Solutions:
(n, k) = map(int, input().split())
tuk = n - k
hell = 998244353
if tuk <= 0:
	print(0)
	exit(0)
fact = [1] * 200005
for i in range(2, 200005):
	fact[i] = i * fact[i - 1] % hell

def C(n, r):
	ans = 1
	ans = fact[r] * fact[n - r] % hell
	ans = fact[n] * pow(ans, hell - 2, hell) % hell
	return ans
ans = C(n, tuk)
if k != 0:
	ans *= 2
res = 0
for i in range(tuk):
	t = C(tuk, i) * pow(tuk - i, n, hell) % hell
	if i % 2:
		res = (res - t + hell) % hell
	else:
		res = (res + t) % hell
ans = ans * res % hell
print(ans)


MOD = 998244353
list_size = 200001
f_list = [1] * list_size
f_r_list = [1] * list_size
for i in range(list_size - 1):
	f_list[i + 1] = int(f_list[i] * (i + 2) % MOD)
f_r_list[-1] = pow(f_list[-1], MOD - 2, MOD)
for i in range(2, list_size + 1):
	f_r_list[-i] = int(f_r_list[-i + 1] * (list_size + 2 - i) % MOD)

def comb(n, r):
	if n < r:
		return 0
	elif n == 0 or r == 0 or n == r:
		return 1
	else:
		return f_list[n - 1] * f_r_list[n - r - 1] % MOD * f_r_list[r - 1] % MOD
(n, k) = map(int, input().split())
if k >= n:
	print(0)
elif k == 0:
	print(f_list[n - 1])
else:
	ans = 0
	m = n - k
	for i in range(1, m + 1):
		ans += (-1) ** ((m - i) % 2) * pow(i, n, MOD) * comb(m, i)
		ans %= MOD
	ans *= f_r_list[m - 1] * f_list[n - 1] * f_r_list[k - 1]
	ans *= 2
	print(ans % MOD)


(n, k) = map(int, input().split())

def cmb(n, r, mod):
	if r < 0 or r > n:
		return 0
	r = min(r, n - r)
	return g1[n] * g2[r] * g2[n - r] % mod
mod = 998244353
N = 200000
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range(2, N + 1):
	g1.append(g1[-1] * i % mod)
	inverse.append(-inverse[mod % i] * (mod // i) % mod)
	g2.append(g2[-1] * inverse[-1] % mod)
if k == 0:
	ans = 1
	for i in range(1, n + 1):
		ans *= i
		ans %= mod
	print(ans)
elif k >= n:
	print(0)
else:
	ans = 0
	K = n - k
	for i in range(K + 1):
		ans += (-1) ** ((K - i) % 2) * cmb(K, i, mod) * pow(i, n, mod)
	ans %= mod
	ans *= cmb(n, n - k, mod)
	ans *= 2
	ans %= mod
	print(ans)


def prepare(n, MOD):
	f = 1
	factorials = [1]
	for m in range(1, n + 1):
		f *= m
		f %= MOD
		factorials.append(f)
	inv = pow(f, MOD - 2, MOD)
	invs = [1] * (n + 1)
	invs[n] = inv
	for m in range(n, 1, -1):
		inv *= m
		inv %= MOD
		invs[m - 1] = inv
	return (factorials, invs)

def solve(n, k):
	MOD = 998244353
	if k == 0:
		ans = 1
		for i in range(2, n + 1):
			ans = ans * i % MOD
		return ans
	if k > n - 1:
		return 0
	(facts, invs) = prepare(n, MOD)
	use_row = n - k
	t = 1
	ans = 0
	for r in range(use_row, 0, -1):
		ans = (ans + t * facts[use_row] * invs[r] * invs[use_row - r] * pow(r, n, MOD)) % MOD
		t *= -1
	return ans * 2 * facts[n] * invs[use_row] * invs[n - use_row] % MOD
(n, k) = list(map(int, input().split()))
print(solve(n, k))


import sys
from functools import reduce
ints = (int(x) for x in sys.stdin.read().split())
mod = 998244353

def mod_pow(a, k):
	r = 1
	while k and r:
		if k % 2:
			r = r * a % mod
		(k, a) = (k >> 1, a * a % mod)
	return r

def main():
	mul = lambda a, b: a * b % mod

	def nCk(n, k):
		assert 0 <= k <= n
		return mul(fact[n], mod_pow(mul(fact[k], fact[n - k]), mod - 2))
	(n, k) = (next(ints), next(ints))
	if 0 <= k < n:
		fact = [1] * (n + 1)
		for i in range(1, n + 1):
			fact[i] = mul(fact[i - 1], i)
		(m, ans) = (n - k, 0)
		for i in range(m):
			sign = 1 if i % 2 == 0 else -1
			ans += sign * mul(nCk(m, i), mod_pow(m - i, n))
			ans %= mod
		ans = mul(ans, nCk(n, k))
		ans = mul(ans, 1 + (k > 0))
	else:
		ans = 0
	print(ans)
	return
main()


from sys import stdin
from sys import stdout
m = 998244353
factorial = [1]
for i in range(1, 200001):
	factorial.append(factorial[i - 1] * i % m)

def quick_power(a, n):
	if n == 0:
		return 1
	x = quick_power(a, n // 2) % m
	x = x * x % m
	if n % 2 == 1:
		x = x * a % m
	return x

def inv(b):
	return quick_power(b, m - 2)

def combinatoria(a, b):
	x = factorial[a] * inv(factorial[b]) % m * inv(factorial[a - b]) % m
	return x

def PlacingRooks(n, k):
	if k == 0:
		return factorial[n]
	elif k >= n:
		return 0
	else:
		c = n - k
		result = 0
		for i in range(0, c):
			aux = quick_power(-1, i) * combinatoria(c, i) * quick_power(c - i, n) % m
			result = (result + aux) % m
		result = result * combinatoria(n, c) % m * 2 % m
		return result
input = list(map(int, stdin.readline().split()))
n = input[0]
k = input[1]
stdout.write(str(PlacingRooks(n, k)) + '\n')


MOD = 998244353
(n, k) = map(int, input().split())
x = n - k
num = 1
den = 1
s = 0
tden = 1
for i in range(x):
	v = pow(x - i, n, MOD) * num
	s = (s * den + (-1) ** i * v * tden) % MOD
	tden = tden * den % MOD
	num = num * (x - i) % MOD
	den = den * (i + 1) % MOD
num = 1
den = 1
for i in range(x):
	num = num * (n - i) % MOD
	den = den * (i + 1) % MOD
s = (1 + (k != 0)) * s * num * pow(den * tden, MOD - 2, MOD) % MOD
print(s)


fact = [1]
mod = 998244353
for i in range(1, 200001):
	fact.append(fact[-1] * i % mod)
(n, k) = map(int, input().split())
same = k

def choose(n, r):
	return fact[n] * pow(fact[r], mod - 2, mod) * pow(fact[n - r], mod - 2, mod) % mod

def sterling(n, m):
	result = 0
	for i in range(n):
		if i % 2 == 0:
			result = (result + choose(n, i) * pow(n - i, m, mod)) % mod
		else:
			result = (result - choose(n, i) * pow(n - i, m, mod)) % mod
	return result % mod
if k > n - 1:
	print(0)
elif k == 0:
	print(fact[n])
else:
	print(2 * choose(n, n - k) * sterling(n - k, n) % mod)


MOD = 998244353

def inv(x):
	return pow(x, MOD - 2, MOD)
(n, k) = list(map(int, input().split()))
if k >= n:
	print(0)
else:
	out = 0
	col = n - k
	binom = 1
	mult = 1
	for i in range(n, col, -1):
		mult *= i
		mult *= inv(n + 1 - i)
		mult %= MOD
	for i in range(col, 0, -1):
		out += binom * pow(i, n, MOD)
		out %= MOD
		binom *= i
		binom *= inv(col + 1 - i)
		binom *= -1
		binom %= MOD
	out *= mult
	if k > 0:
		out *= 2
	print(out % MOD)


import sys
input = sys.stdin.buffer.readline

def print(val):
	sys.stdout.write(str(val) + '\n')

def inverse(n, primemod):
	return pow(n, primemod - 2, primemod)

def choose(n, k, mod, factorials, inverses):
	return factorials[n] * inverses[k] * inverses[n - k] % mod

def factorial_creator(n, mod):
	factorials = [1]
	curr = 1
	for i in range(1, n + 1):
		curr = curr * i % mod
		factorials.append(curr)
	return factorials

def inverse_creator(n, k, mod, factorials):
	inverses = [1 for i in range(n - k + 1)]
	current = inverse(factorials[n - k], mod)
	inverses[n - k] = current
	for i in range(n - k, 0, -1):
		current = current * i % mod
		inverses[i - 1] = current
	return inverses

def place_rooks(n, k, mod):
	if k >= n:
		return 0
	factorials = factorial_creator(n, 998244353)
	inverses = inverse_creator(n, k, 998244353, factorials)
	filled = n - k
	placements_per_filled = 0
	for i in range(filled):
		placements_per_filled += (-1) ** i * choose(filled, i, mod, factorials, inverses) * pow(filled - i, n, mod) % mod
		placements_per_filled %= mod
	if k == 0:
		total = factorials[n] * inverses[n - k] * inverse(factorials[k], mod) % mod * placements_per_filled % mod
		return total
	total = 2 * (factorials[n] * inverses[n - k] * inverse(factorials[k], mod)) % mod * placements_per_filled % mod
	return total
(n, k) = map(int, input().split())
print(place_rooks(n, k, 998244353))


import sys
input = sys.stdin.readline
mod = 998244353

def cmb(n, r):
	if r < 0 or r > n:
		return 0
	r = min(r, n - r)
	return g1[n] * g2[r] * g2[n - r] % mod
NNN = 2 * 10 ** 5
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range(2, NNN + 1):
	g1.append(g1[-1] * i % mod)
	inverse.append(-inverse[mod % i] * (mod // i) % mod)
	g2.append(g2[-1] * inverse[-1] % mod)
(N, K) = map(int, input().split())
if K > N:
	print(0)
else:
	M = N - K
	R = 0
	for i in range(1, M + 1):
		R += (-1 if (M - i) % 2 else 1) * cmb(M, i) * pow(i, N, mod) % mod
	R = R * cmb(N, M) % mod
	if K != 0:
		R = R * 2 % mod
	print(R)


MAX = 2 * 10 ** 5 + 100
MOD = 998244353
fact = [0] * MAX
inv = [0] * MAX
finv = [0] * MAX
fact[0] = 1
fact[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
for i in range(2, MAX):
	fact[i] = fact[i - 1] * i % MOD
	inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
	finv[i] = finv[i - 1] * inv[i] % MOD

def C(n, r):
	if n < r:
		return 0
	if n < 0 or r < 0:
		return 0
	return fact[n] * (finv[r] * finv[n - r] % MOD) % MOD
(n, k) = map(int, input().split())
if k >= n:
	print(0)
	exit()
if k == 0:
	print(fact[n])
	exit()
ans = 0
for i in range(n - k + 1):
	if i % 2 == 0:
		ans += C(n - k, i) * pow(n - k - i, n, MOD)
		ans %= MOD
	else:
		ans -= C(n - k, i) * pow(n - k - i, n, MOD)
		ans %= MOD
ans *= 2 * C(n, k)
ans %= MOD
print(ans)


import sys
input = sys.stdin.readline
(fact, inv_fact) = ([0] * (2 * 10 ** 5 + 1), [0] * (2 * 10 ** 5 + 1))
fact[0] = 1
mod = 998244353

def make_nCr_mod(max_n=2 * 10 ** 5, mod=998244353):
	global fact
	global inv_fact
	for i in range(max_n):
		fact[i + 1] = fact[i] * (i + 1) % mod
	inv_fact[-1] = pow(fact[-1], mod - 2, mod)
	for i in reversed(range(max_n)):
		inv_fact[i] = inv_fact[i + 1] * (i + 1) % mod
make_nCr_mod()

def nCr_mod(n, r):
	res = 1
	while n or r:
		(a, b) = (n % mod, r % mod)
		if a < b:
			return 0
		res = res * fact[a] % mod * inv_fact[b] % mod * inv_fact[a - b] % mod
		n //= mod
		r //= mod
	return res
(n, k) = map(int, input().split())
if k == 0:
	print(fact[n])
elif k >= n:
	print(0)
else:
	ans = 0
	for i in range(1, n - k + 1):
		ans += 2 * nCr_mod(n, k) * pow(-1, n - k - i) * nCr_mod(n - k, i) * pow(i, n, mod) % mod
	print(ans % mod)


def inverse(n, primemod):
	return pow(n, primemod - 2, primemod)

def choose(n, k, mod, factorials, inverses):
	return factorials[n] * inverses[k] * inverses[n - k] % mod

def factorial_creator(n, mod):
	factorials = [1]
	curr = 1
	for i in range(1, n + 1):
		curr = curr * i % mod
		factorials.append(curr)
	return factorials

def inverse_creator(n, k, mod, factorials):
	inverses = [1 for i in range(n - k + 1)]
	current = inverse(factorials[n - k], mod)
	inverses[n - k] = current
	for i in range(n - k, 0, -1):
		current = current * i % mod
		inverses[i - 1] = current
	return inverses

def place_rooks(n, k, mod):
	if k >= n:
		return 0
	factorials = factorial_creator(n, 998244353)
	inverses = inverse_creator(n, k, 998244353, factorials)
	filled = n - k
	placements_per_filled = 0
	for i in range(filled):
		placements_per_filled += (-1) ** i * choose(filled, i, mod, factorials, inverses) * pow(filled - i, n, mod) % mod
		placements_per_filled %= mod
	if k == 0:
		total = factorials[n] * inverses[n - k] * inverse(factorials[k], mod) % mod * placements_per_filled % mod
		return total
	total = 2 * (factorials[n] * inverses[n - k] * inverse(factorials[k], mod)) % mod * placements_per_filled % mod
	return total
(n, k) = map(int, input().split())
print(place_rooks(n, k, 998244353))


from sys import stdin, stdout
MOD = 998244353
f_a = []

def build_fac(n):
	f_a.append(1)
	for i in range(1, n + 1):
		r = i * f_a[-1]
		r %= MOD
		f_a.append(r)

def fac(n):
	return f_a[n]

def inv(n):
	return bpow(n, MOD - 2)

def bpow(a, b):
	if b == 0:
		return 1
	r = bpow(a, b // 2)
	r *= r
	r %= MOD
	if b % 2 == 1:
		r *= a
		r %= MOD
	return r

def C(n, c):
	r1 = fac(n)
	r2 = inv(fac(c))
	r3 = inv(fac(n - c))
	r = r1 * r2
	r %= MOD
	r *= r3
	r %= MOD
	return r

def placing_rooks(n, k):
	if k > n:
		return 0
	r = 0
	for i in range(n - k):
		r1 = bpow(n - k - i, n)
		r1 *= C(n - k, i)
		r1 %= MOD
		if i % 2 == 0:
			r += r1
		else:
			r -= r1
		r %= MOD
	r *= C(n, n - k)
	r %= MOD
	if k > 0:
		r *= 2
		r %= MOD
	return r
(n, k) = map(int, stdin.readline().split())
build_fac(n)
r = placing_rooks(n, k)
stdout.write(str(r) + '\n')


def comb(n, k):
	return L[n] * pow(L[n - k] * L[k], m - 2, m) % m
(n, k) = map(int, input().split())
if k >= n:
	print(0)
else:
	m = 998244353
	L = [1]
	for i in range(1, n + 1):
		L.append(L[-1] * i % m)
	c = 0
	for i in range(n - k):
		c += (-1) ** i * pow(n - k - i, n, m) * comb(n - k, n - k - i) % m
	c %= m
	c *= comb(n, n - k)
	if k == 0:
		print(c % m)
	else:
		print(c * 2 % m)


MOD = 998244353
fac = [1] * (2 * 10 ** 5 + 10)

def comb(n, k):
	return fac[n] * pow(fac[n - k], MOD - 2, MOD) * pow(fac[k], MOD - 2, MOD) % MOD
for i in range(len(fac) - 1):
	fac[i + 1] = fac[i] * (i + 1) % MOD
(n, k) = list(map(int, input().split()))
if k == 0:
	print(fac[n])
else:
	k = n - k
	if k <= 0:
		print(0)
		return
	ans = 0
	for i in range(k + 1):
		t = comb(k, i) * pow(k - i, n, MOD) % MOD
		if i % 2:
			ans -= t
		else:
			ans += t
	print(2 * ans * comb(n, k) % MOD)


nn = 200200
P = 998244353
fa = [1] * (nn + 1)
fainv = [1] * (nn + 1)
for i in range(nn):
	fa[i + 1] = fa[i] * (i + 1) % P
fainv[-1] = pow(fa[-1], P - 2, P)
for i in range(nn)[::-1]:
	fainv[i] = fainv[i + 1] * (i + 1) % P
C = lambda a, b: fa[a] * fainv[b] % P * fainv[a - b] % P if 0 <= b <= a else 0
(N, K) = map(int, input().split())
if K == 0:
	print(fa[N])
	exit()
if K >= N:
	print(0)
	exit()
a = N - K
ans = 0
for i in range(a + 1):
	ans = (ans + pow(a - i, N, P) * C(a, i) * (-1 if i & 1 else 1)) % P
ans = ans * 2 * C(N, a) % P
print(ans)


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
import sys

def solve(n, k):
	mod = 998244353
	if k == 0:
		ans = 1
		for i in range(1, n + 1):
			ans *= i
			ans %= mod
		return ans
	if k >= n:
		return 0
	inv = lambda x: pow(x, mod - 2, mod)
	Fact = [1]
	for i in range(1, n + 1):
		Fact.append(Fact[i - 1] * i % mod)
	Finv = [0] * (n + 1)
	Finv[-1] = inv(Fact[-1])
	for i in range(n - 1, -1, -1):
		Finv[i] = Finv[i + 1] * (i + 1) % mod

	def comb(n, r):
		if n < r:
			return 0
		return Fact[n] * Finv[r] * Finv[n - r] % mod
	m = n - k
	t = 1
	ans = 0
	for r in range(m, 0, -1):
		ans += t * comb(m, r) * pow(r, n, mod)
		ans %= mod
		t *= -1
	ans *= comb(n, m) * 2
	ans %= mod
	return ans

def main():
	(n, k) = map(int, input().split())
	ans = solve(n, k)
	sys.stdout.write(str(ans) + '\n')
main()


MOD = 998244353
N = 200007
fac = [1] * N
for i in range(1, N):
	fac[i] = i * fac[i - 1] % MOD

def inv(n):
	return pow(n, MOD - 2, MOD)

def nCk(n, k):
	return fac[n] * inv(fac[k] * fac[n - k] % MOD) % MOD

def nSk(n, k):
	res = 0
	for i in range(1, k + 1):
		res = (res + pow(-1, k - i) * nCk(k, i) * pow(i, n, MOD)) % MOD
	return res
(n, k) = map(int, input().split())
res = None
if k == 0:
	res = fac[n]
elif k >= n:
	res = 0
else:
	res = 2 * nCk(n, k) * nSk(n, n - k) % MOD
print(res)


def read_int():
	return int(input())

def read_ints():
	return list(map(int, input().split(' ')))
fac = [1]
rev = []
mod = 998244353

def fexp(x, y):
	ans = 1
	while y > 0:
		if y % 2 == 1:
			ans = ans * x % mod
		x = x * x % mod
		y //= 2
	return ans

def comb(n, k):
	return fac[n] * rev[k] * rev[n - k] % mod
(n, k) = read_ints()
if k >= n:
	print(0)
else:
	for i in range(1, n + 5):
		fac.append(fac[-1] * i % mod)
	for i in range(n + 5):
		rev.append(fexp(fac[i], mod - 2))
	if k == 0:
		print(fac[n])
	else:
		ways = comb(n, k)
		col = 0
		for i in range(n - k):
			sign = 1 if i % 2 == 0 else -1
			col += sign * comb(n - k, i) * fexp(n - k - i, n)
			col %= mod
			if col < 0:
				col += mod
		print(ways * col * 2 % mod)


class Combination:

	def __init__(self, n_max, mod=10 ** 9 + 7):
		self.mod = mod
		f = 1
		self.fac = fac = [f]
		for i in range(1, n_max + 1):
			f = f * i % mod
			fac.append(f)
		f = pow(f, mod - 2, mod)
		self.facinv = facinv = [f]
		for i in range(n_max, 0, -1):
			f = f * i % mod
			facinv.append(f)
		facinv.reverse()

	def __call__(self, n, r):
		return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod

	def C(self, n, r):
		if not 0 <= r <= n:
			return 0
		return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod

	def P(self, n, r):
		if not 0 <= r <= n:
			return 0
		return self.fac[n] * self.facinv[n - r] % self.mod

	def H(self, n, r):
		if n == 0 and r > 0 or r < 0:
			return 0
		return self.fac[n + r - 1] * self.facinv[r] % self.mod * self.facinv[n - 1] % self.mod

	def rising_factorial(self, n, r):
		return self.fac[n + r - 1] * self.facinv[n - 1] % self.mod

	def stirling_first(self, n, k):
		if n == k:
			return 1
		if k == 0:
			return 0
		return (self.stirling_first(n - 1, k - 1) + (n - 1) * self.stirling_first(n - 1, k)) % self.mod

	def stirling_second(self, n, k):
		if n == k:
			return 1
		return self.facinv[k] * sum(((-1) ** (k - m) * self.C(k, m) * pow(m, n, self.mod) for m in range(1, k + 1))) % self.mod

	def balls_and_boxes_3(self, n, k):
		return sum(((-1) ** (k - m) * self.C(k, m) * pow(m, n, self.mod) for m in range(1, k + 1))) % self.mod

	def bernoulli(self, n):
		if n == 0:
			return 1
		if n % 2 and n >= 3:
			return 0
		return -pow(n + 1, self.mod - 2, self.mod) * sum((self.C(n + 1, k) * self.bernoulli(k) % self.mod for k in range(n))) % self.mod

	def faulhaber(self, k, n):
		return pow(k + 1, self.mod - 2, self.mod) * sum((self.C(k + 1, j) * self.bernoulli(j) % self.mod * pow(n, k - j + 1, self.mod) % self.mod for j in range(k + 1))) % self.mod

	def lah(self, n, k):
		return self.C(n - 1, k - 1) * self.fac[n] % self.mod * self.facinv[k] % self.mod

	def bell(self, n, k):
		return sum((self.stirling_second(n, j) for j in range(1, k + 1))) % self.mod
(N, K) = map(int, input().split())
mod = 998244353
if K == 0:
	ans = 1
	for i in range(1, N + 1):
		ans = ans * i % mod
	print(ans)
	exit()
if K >= N:
	print(0)
	exit()
comb = Combination(200002, mod=mod)
print(comb.balls_and_boxes_3(N, N - K) * comb(N, K) * 2 % mod)


def modpow(b, e, mod):
	ret = 1
	pw = b
	while e > 0:
		if e % 2 == 1:
			ret = ret * pw % mod
		e = e >> 1
		pw = pw * pw % mod
	return ret
(n, k) = list(map(int, input().split()))
mod = 998244353
inv = [0 for _ in range(n + 1)]
fac = [0 for _ in range(n + 1)]
fac[0] = inv[0] = 1
for i in range(n):
	fac[i + 1] = fac[i] * (i + 1) % mod
	inv[i + 1] = modpow(fac[i + 1], mod - 2, mod)

def nCr(n, r):
	num = fac[n]
	den = inv[r] * inv[n - r] % mod
	return num * den % mod
row = n - k
if row < 0 or row > n:
	print('0')
else:
	ans = 0
	for i in range(row):
		add = nCr(row, i) * modpow(row - i, n, mod) % mod
		if i % 2 == 0:
			ans = ans + add
		else:
			ans = ans - add
	ans = mod + ans % mod
	mult = 2
	if row == n:
		mult = 1
	print(mult * nCr(n, row) * ans % mod)


def modfac(n, MOD):
	f = 1
	factorials = [1]
	for m in range(1, n + 1):
		f *= m
		f %= MOD
		factorials.append(f)
	inv = pow(f, MOD - 2, MOD)
	invs = [1] * (n + 1)
	invs[n] = inv
	for m in range(n, 1, -1):
		inv *= m
		inv %= MOD
		invs[m - 1] = inv
	return (factorials, invs)

def modnCr(n, r, mod, fac, inv):
	return fac[n] * inv[n - r] * inv[r] % mod
(n, k) = map(int, input().split())
mod = 998244353
N = n
if k >= N:
	print(0)
elif k == 0:
	ans = 1
	for i in range(1, N + 1):
		ans *= i
		ans %= mod
	print(ans)
else:
	(fac, inv) = modfac(n * 2 + 10, mod)
	ans = modnCr(n, k, mod, fac, inv)
	r = N - k
	p = N
	na = 0
	for i in range(r):
		now = modnCr(r, i, mod, fac, inv) * pow(r - i, p, mod)
		if i % 2 == 0:
			na += now
		else:
			na -= now
		na %= mod
	print(ans * na * 2 % mod)


from bisect import *
from collections import *
from math import gcd, ceil, sqrt, floor, inf
from heapq import *
from itertools import *
from functools import *
from collections import deque
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc
farr = [1]
ifa = []

def fact(x, mod=0):
	if mod:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr) % mod)
	else:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr))
	return farr[x]

def ifact(x, mod):
	global ifa
	fact(x, mod)
	ifa.append(pow(farr[-1], mod - 2, mod))
	for i in range(x, 0, -1):
		ifa.append(ifa[-1] * i % mod)
	ifa.reverse()

def per(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return fact(i) // fact(i - j)
	return farr[i] * ifa[i - j] % mod

def com(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return per(i, j) // fact(j)
	return per(i, j, mod) * ifa[j] % mod

def catalan(n):
	return com(2 * n, n) // (n + 1)

def isprime(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return False
	return True

def lowbit(n):
	return n & -n

def inverse(a, m):
	a %= m
	if a <= 1:
		return a
	return (1 - inverse(m, a) * m) // a % m

class BIT:

	def __init__(self, arr):
		self.arr = arr
		self.n = len(arr) - 1

	def update(self, x, v):
		while x <= self.n:
			self.arr[x] += v
			x += x & -x

	def query(self, x):
		ans = 0
		while x:
			ans += self.arr[x]
			x &= x - 1
		return ans

class DSU:

	def __init__(self, n):
		self.c = [-1] * n

	def same(self, x, y):
		return self.find(x) == self.find(y)

	def find(self, x):
		if self.c[x] < 0:
			return x
		self.c[x] = self.find(self.c[x])
		return self.c[x]

	def union(self, u, v):
		(u, v) = (self.find(u), self.find(v))
		if u == v:
			return False
		if self.c[u] > self.c[v]:
			(u, v) = (v, u)
		self.c[u] += self.c[v]
		self.c[v] = u
		return True

	def size(self, x):
		return -self.c[self.find(x)]

class UFS:

	def __init__(self, n):
		self.parent = [i for i in range(n)]
		self.ranks = [0] * n

	def find(self, x):
		if x != self.parent[x]:
			self.parent[x] = self.find(self.parent[x])
		return self.parent[x]

	def union(self, u, v):
		(pu, pv) = (self.find(u), self.find(v))
		if pu == pv:
			return False
		if self.ranks[pu] >= self.ranks[pv]:
			self.parent[pv] = pu
			if self.ranks[pv] == self.ranks[pu]:
				self.ranks[pu] += 1
		else:
			self.parent[pu] = pv

def Prime(n):
	c = 0
	prime = []
	flag = [0] * (n + 1)
	for i in range(2, n + 1):
		if not flag[i]:
			prime.append(i)
			c += 1
		for j in range(c):
			if i * prime[j] > n:
				break
			flag[i * prime[j]] = prime[j]
			if i % prime[j] == 0:
				break
	return prime

def dij(s, graph):
	d = {}
	d[s] = 0
	heap = [(0, s)]
	seen = set()
	while heap:
		(dis, u) = heappop(heap)
		if u in seen:
			continue
		seen.add(u)
		for (v, w) in graph[u]:
			if v not in d or d[v] > d[u] + w:
				d[v] = d[u] + w
				heappush(heap, (d[v], v))
	return d

def GP(it):
	return [[ch, len(list(g))] for (ch, g) in groupby(it)]

def lcm(a, b):
	return a * b // gcd(a, b)

class DLN:

	def __init__(self, val):
		self.val = val
		self.pre = None
		self.next = None

def nb(i, j):
	for (ni, nj) in [[i + 1, j], [i - 1, j], [i, j - 1], [i, j + 1]]:
		if 0 <= ni < n and 0 <= nj < m:
			yield (ni, nj)

@bootstrap
def gdfs(r, p):
	if len(g[r]) == 1 and p != -1:
		yield None
	for ch in g[r]:
		if ch != p:
			yield gdfs(ch, r)
	yield None

def topo(n):
	q = deque()
	res = []
	for i in range(1, n + 1):
		if ind[i] == 0:
			q.append(i)
			res.append(i)
	while q:
		u = q.popleft()
		for v in g[u]:
			ind[v] -= 1
			if ind[v] == 0:
				q.append(v)
				res.append(v)
	return res

def cal(x):
	(d, m) = divmod(x, p)
	ans = d * b
	if m:
		if m < b:
			ans += m
		else:
			ans += b - 1
	return ans
t = 1
for i in range(t):
	(n, k) = RL()
	ans = 0
	mod = 998244353
	ifact(n, mod)
	if k == 0:
		ans = fact(n, mod)
	elif k >= n:
		ans = 0
	else:
		c = n - k
		ans = 0
		for i in range(c):
			if not i & 1:
				ans += com(c, i, mod) * pow(c - i, n, mod) % mod
			else:
				ans -= com(c, i, mod) * pow(c - i, n, mod) % mod
			ans %= mod
		ans = ans * 2 * com(n, c, mod) % mod
	print(ans)


class Combination:

	def __init__(self, n, MOD):
		self.fact = [1]
		for i in range(1, n + 1):
			self.fact.append(self.fact[-1] * i % MOD)
		self.inv_fact = [0] * (n + 1)
		self.inv_fact[n] = pow(self.fact[n], MOD - 2, MOD)
		for i in reversed(range(n)):
			self.inv_fact[i] = self.inv_fact[i + 1] * (i + 1) % MOD
		self.MOD = MOD

	def factorial(self, k):
		return self.fact[k]

	def inverse_factorial(self, k):
		return self.inv_fact[k]

	def permutation(self, k, r):
		if k < r:
			return 0
		return self.fact[k] * self.inv_fact[k - r] % self.MOD

	def combination(self, k, r):
		if k < r:
			return 0
		return self.fact[k] * self.inv_fact[k - r] * self.inv_fact[r] % self.MOD
(n, k) = map(int, input().split())
MOD = 998244353
comb = Combination(10 ** 6, MOD)
ball = n
box = n - k
if box <= 0:
	print(0)
	return
ans = 0
for i in range(box + 1):
	ans += pow(-1, i, MOD) * comb.combination(box, i) * pow(box - i, ball, MOD)
	ans %= MOD
if k == 0:
	print(ans * comb.combination(n, box) % MOD)
else:
	print(ans * comb.combination(n, box) * 2 % MOD)


mod = 998244353
eps = 10 ** (-9)

def main():
	import sys
	input = sys.stdin.readline
	nmax = 2 * 10 ** 5 + 10
	fac = [0] * nmax
	finv = [0] * nmax
	inv = [0] * nmax
	fac[0] = 1
	fac[1] = 1
	finv[0] = 1
	finv[1] = 1
	inv[1] = 1
	for i in range(2, nmax):
		fac[i] = fac[i - 1] * i % mod
		inv[i] = mod - inv[mod % i] * (mod // i) % mod
		finv[i] = finv[i - 1] * inv[i] % mod

	def comb(n, r):
		if n < r:
			return 0
		else:
			return fac[n] * (finv[r] * finv[n - r] % mod) % mod
	(N, K) = map(int, input().split())
	if K >= N:
		print(0)
		exit()
	ans = 0
	flg = 1
	for i in range(N - K, 0, -1):
		ans = (ans + flg * comb(N - K, i) * pow(i, N, mod)) % mod
		flg *= -1
	ans = ans * comb(N, N - K) % mod
	if K:
		ans = ans * 2 % mod
	print(ans)
main()


mod = 998244353
(n, k) = map(int, input().split())
fact = [1]
for i in range(1, n + 1):
	fact.append(fact[-1] * i % mod)
revfact = [1]
for i in range(1, n + 1):
	revfact.append(pow(fact[i], mod - 2, mod))
if k >= n:
	print(0)
elif k == 0:
	print(fact[n])
else:
	ans = 0
	for i in range(n - k + 1):
		if i % 2 == 0:
			ans += pow(n - k - i, n, mod) * fact[n - k] * revfact[i] * revfact[n - k - i]
			ans %= mod
		else:
			ans -= pow(n - k - i, n, mod) * fact[n - k] * revfact[i] * revfact[n - k - i]
			ans %= mod
	print(ans * fact[n] * revfact[k] * revfact[n - k] * 2 % mod)


import sys
readline = sys.stdin.readline
MOD = 998244353

def frac(limit):
	frac = [1] * limit
	for i in range(2, limit):
		frac[i] = i * frac[i - 1] % MOD
	fraci = [None] * limit
	fraci[-1] = pow(frac[-1], MOD - 2, MOD)
	for i in range(-2, -limit - 1, -1):
		fraci[i] = fraci[i + 1] * (limit + i + 1) % MOD
	return (frac, fraci)
(frac, fraci) = frac(1341398)

def comb(a, b):
	if not a >= b >= 0:
		return 0
	return frac[a] * fraci[b] * fraci[a - b] % MOD
(N, K) = map(int, readline().split())
if K == 0:
	print(frac[N])
elif K >= N:
	print(0)
else:
	res = 0
	for i in range(N - K, 0, -1):
		res = (res + comb(N - K, i) * (-1) ** ((N - K - i) % 2) * pow(i, N, MOD)) % MOD
	print(2 * comb(N, N - K) * res % MOD)