AtCoder Grand Contest 005 - ~K Perm Counting

Snuke loves permutations. He is making a permutation of length N.

Since he hates the integer K, his permutation will satisfy the following:

* Let the permutation be a_1, a_2, ..., a_N. For each i = 1,2,...,N, |a_i - i| \neq K.



Among the N! permutations of length N, how many satisfies this condition?

Since the answer may be extremely large, find the answer modulo 924844033(prime).

Constraints

* 2 ≦ N ≦ 2000
* 1 ≦ K ≦ N-1

Input

The input is given from Standard Input in the following format:


N K


Output

Print the answer modulo 924844033.

Examples

Input

3 1


Output

2


Input

4 1


Output

5


Input

4 2


Output

9


Input

4 3


Output

14


Input

425 48


Output

756765083

Difficulty: UNKNOWN_DIFFICULTY

Starter code:

Solutions:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
sys.setrecursionlimit(2147483647)
INF = 10 ** 13

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

def I():
	return int(sys.stdin.readline())

def LS():
	return sys.stdin.readline().rstrip().split()

def S():
	return sys.stdin.readline().rstrip()

def IR(n):
	return [I() for i in range(n)]

def LIR(n):
	return [LI() for i in range(n)]

def SR(n):
	return [S() for i in range(n)]

def LSR(n):
	return [LS() for i in range(n)]

def SRL(n):
	return [list(S()) for i in range(n)]

def MSRL(n):
	return [[int(j) for j in list(S())] for i in range(n)]
mod = 924844033
(n, k) = LI()
fac = [1] * (n + 1)
for j in range(1, n + 1):
	fac[j] = fac[j - 1] * j % mod
dp = [[0] * 2 for _ in range(n + 1)]
dp[0][0] = 1
last = 0
for i in range(min(n, 2 * k)):
	idx = i
	while idx < n:
		ndp = [[0] * 2 for _ in range(n + 1)]
		if idx == i:
			for ll in range(n + 1):
				dp[ll][0] += dp[ll][1]
				dp[ll][1] = 0
		for l in range(1, n + 1):
			ndp[l][0] = sum(dp[l])
			if idx - k >= 0:
				ndp[l][0] += dp[l - 1][0]
			if idx + k < n:
				ndp[l][1] = sum(dp[l - 1])
			ndp[l][0] %= mod
		ndp[0][0] = 1
		dp = ndp
		idx += 2 * k
ans = fac[n]
for m in range(1, n + 1):
	if m % 2:
		ans -= sum(dp[m]) * fac[n - m] % mod
	else:
		ans += sum(dp[m]) * fac[n - m] % mod
	ans %= mod
print(ans)


from functools import reduce
mod = 924844033
frac = [1] * 5555
for i in range(2, 5555):
	frac[i] = i * frac[i - 1] % mod
fraci = [None] * 5555
fraci[-1] = pow(frac[-1], mod - 2, mod)
for i in range(-2, -5555, -1):
	fraci[i] = fraci[i + 1] * (5555 + i + 1) % mod
(N, K) = map(int, input().split())
dp = [[[0] * 3 for _ in range(N)] for _ in range(-(-N // (2 * K)) + 1)]

def merge(A, B):
	C = [0] * (len(A) + len(B) - 1)
	for i in range(len(A)):
		for j in range(len(B)):
			C[i + j] = (C[i + j] + A[i] * B[j]) % mod
	return C
for j in range(min(N, 2 * K)):
	dp[0][j][2] = 1
	if j + K <= N - 1:
		dp[1][j][0] = 1
	if j - K >= 0:
		dp[1][j][1] = 1
for i in range(-(-N // (2 * K)) + 1):
	for j in range(N):
		if j + 2 * K > N - 1:
			break
		r = dp[i][j][0]
		l = dp[i][j][1]
		n = dp[i][j][2]
		if i == -(-N // (2 * K)):
			dp[i][j + 2 * K][2] = (dp[i][j + 2 * K][2] + r + l + n) % mod
			continue
		if j + 3 * K <= N - 1:
			dp[i + 1][j + 2 * K][0] = (dp[i + 1][j + 2 * K][0] + r + l + n) % mod
		dp[i][j + 2 * K][2] = (dp[i][j + 2 * K][2] + r + l + n) % mod
		dp[i + 1][j + 2 * K][1] = (dp[i + 1][j + 2 * K][1] + l + n) % mod
Ans = []
for j in range(min(2 * K, N)):
	j = -1 - j
	Ans.append([sum(dp[i][j]) for i in range(-(-N // (2 * K)) + 1)])
A = reduce(merge, Ans)
A = [(-1) ** i * frac[N - i] * a % mod for (i, a) in enumerate(A)]
print(sum(A) % mod)


from collections import defaultdict
(n, k) = map(int, input().split())
mod = 924844033
rng = 2010
fctr = [1]
finv = [1]
for i in range(1, rng):
	fctr.append(fctr[-1] * i % mod)
for i in range(1, rng):
	finv.append(pow(fctr[i], mod - 2, mod))

def cmb(n, k):
	if n < 0 or k < 0:
		return 0
	else:
		return fctr[n] * finv[n - k] * finv[k] % mod
if (n - k) * 2 <= n:
	x = (n - k) * 2
	ans = 0
	for i in range(x + 1):
		if i % 2 == 0:
			ans += cmb(x, i) * fctr[n - i]
		else:
			ans -= cmb(x, i) * fctr[n - i]
		ans %= mod
	print(ans)
	exit()
dc = defaultdict(int)
for j in range(1, k + 1):
	a = j
	b = k + j
	cnt = 0
	while a <= n and b <= n:
		if a > b:
			b += 2 * k
		else:
			a += 2 * k
		cnt += 1
	dc[cnt] += 2
nn = (n - k) * 2
cp = set()
cpp = 1
for (i, x) in dc.items():
	for j in range(x):
		cpp += i
		cp.add(cpp)
cp.add(1)
dp = [[0 for j in range(n + 1)] for i in range(nn + 1)]
dp[0][0] = 1
for i in range(1, nn + 1):
	dp[i] = dp[i - 1][:]
	if i not in cp:
		for j in range(1, min(i, n) + 1):
			dp[i][j] += dp[i - 2][j - 1]
			dp[i][j] %= mod
	else:
		for j in range(1, min(i, n) + 1):
			dp[i][j] += dp[i - 1][j - 1]
			dp[i][j] %= mod
ans = 0
for i in range(n + 1):
	if i % 2 == 0:
		ans += fctr[n - i] * dp[nn][i]
	else:
		ans -= fctr[n - i] * dp[nn][i]
	ans %= mod
print(ans)