Problem:
 Score : 900 points    Problem Statement 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 .        Sample Input 1 3 1      Sample Output 1 2  2 permutations (1, 2, 3) , (3, 2, 1) satisfy the condition.       Sample Input 2 4 1      Sample Output 2 5  5 permutations (1, 2, 3, 4) , (1, 4, 3, 2) , (3, 2, 1, 4) , (3, 4, 1, 2) , (4, 2, 3, 1) satisfy the condition.       Sample Input 3 4 2      Sample Output 3 9       Sample Input 4 4 3      Sample Output 4 14       Sample Input 5 425 48      Sample Output 5 756765083

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

import numpy as np

MOD = 924844033

def cumprod(arr,MOD):
    L = len(arr); Lsq = int(L**.5+1)
    arr = np.resize(arr,Lsq**2).reshape(Lsq,Lsq)
    for n in range(1,Lsq):
        arr[:,n] *= arr[:,n-1]; arr[:,n] %= MOD
    for n in range(1,Lsq):
        arr[n] *= arr[n-1,-1]; arr[n] %= MOD
    return arr.ravel()[:L]

def make_fact(U,MOD):
    x = np.arange(U,dtype=np.int64); x[0] = 1
    fact = cumprod(x,MOD)
    x = np.arange(U,0,-1,dtype=np.int64); x[0] = pow(int(fact[-1]),MOD-2,MOD)
    fact_inv = cumprod(x,MOD)[::-1]
    return fact,fact_inv




N,K = map(int,readline().split())

dp_0 = np.zeros((N+1,N+1),np.int64) 
dp_1 = np.zeros((N+1,N+1),np.int64) 
dp_2 = np.zeros((N+1,N+1),np.int64) 
dp_0[0,0] = 1
dp_1[0,0] = 1
dp_2[0,0] = 1
for n in range(1,N+1):
    
    dp_1[n,1:] += dp_1[n-1,:-1]
    dp_2[n,1:] += dp_2[n-1,:-1]
    
    if n >= 2:
        dp_0[n,1:] += dp_0[n-1,:-1]
        dp_1[n,1:] += dp_0[n-1,:-1]
    dp_2[n,1:] += dp_1[n-1,:-1]
    
    dp_0[n] += dp_1[n-1]
    dp_1[n] += dp_1[n-1]
    dp_2[n] += dp_2[n-1]
    dp_0[n] %= MOD
    dp_1[n] %= MOD
    dp_2[n] %= MOD

def F(N,K,n):
    
    items = (N-n)//(2*K)+1
    last = n + (items-1)*(2*K)
    x = (n-K>0) + (last+K<=N)
    arr = dp_0 if x == 0 else (dp_1 if x == 1 else dp_2)
    return arr[items][:items+1]

def convolve(x,y):
    Lx = len(x)
    Ly = len(y)
    if Lx < Ly:
        x,y = y,x
        Lx,Ly = Ly,Lx
    arr = np.zeros(Lx+Ly-1,np.int64)
    for n in range(Ly):
        arr[n:n+Lx] += y[n] * x % MOD
    arr %= MOD
    return arr

x = np.array([1],np.int64)
for n in range(1,2*K+1):
    if n > N:
        break
    x = convolve(x,F(N,K,n))

fact, _ = make_fact(N+100,MOD)

L = len(x)
x[1::2] *= (-1)
answer = (x[::-1] * fact[N-L+1:N+1] % MOD).sum() % MOD
print(answer)

Solution (Python):
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)