Problem:
 Score : 600 points    Problem Statement Let us define the oddness of a permutation p = { p_1,\ p_2,\ ...,\ p_n } of { 1,\ 2,\ ...,\ n } as \sum_{i = 1}^n |i - p_i| .  Find the number of permutations of { 1,\ 2,\ ...,\ n } of oddness k , modulo 10^9+7 .      Constraints  All values in input are integers.  1 \leq n \leq 50  0 \leq k \leq n^2         Input Input is given from Standard Input in the following format:  n  k       Output Print the number of permutations of { 1,\ 2,\ ...,\ n } of oddness k , modulo 10^9+7 .        Sample Input 1 3 2      Sample Output 1 2  There are six permutations of { 1,\ 2,\ 3 }. Among them, two have oddness of 2 :  { 2,\ 1,\ 3 } and { 1,\ 3,\ 2 }.       Sample Input 2 39 14      Sample Output 2 74764168

Solution (Python):
def f_permutation_oddness(N, K, MOD=10**9 + 7):
    
    from itertools import product

    
    
    
    
    if K % 2 == 1:
        return 0

    
    dp = [[[0 for k in range(K + 1)]
           for j in range(N + 2)]
          for i in range(N + 1)]
    dp[0][0][0] = 1
    for i, j, k in product(range(1, N + 1), range(N + 1), range(K + 1)):
        k_previous = k - 2 * j
        if k_previous < 0:
            continue
        dp[i][j][k] += (2 * j + 1) * dp[i - 1][j][k_previous]
        dp[i][j][k] += (j + 1)**2 * dp[i - 1][j + 1][k_previous]
        if j > 0:
            dp[i][j][k] += dp[i - 1][j - 1][k_previous]
        dp[i][j][k] %= MOD
    return dp[N][0][K]

N, K = [int(i) for i in input().split()]
print(f_permutation_oddness(N, K))

Solution (Python):

import sys
from itertools import product

MOD = 1000000007  

def solve(N: int, K: int):
    if K % 2 == 1:
        print(0)
        return
    dp = [[[0 for k in range(K+1)]
            for j in range(N+2)]
            for i in range(N+1)]
    dp[0][0][0] = 1
    for i, j, k in product(range(1, N+1), range(N+1), range(K+1)):
        prev_k = k - 2 * j
        if prev_k < 0:
            continue
        dp[i][j][k] += dp[i-1][j][prev_k]
        dp[i][j][k] += 2 * j * dp[i-1][j][prev_k]
        dp[i][j][k] += (j+1) * (j+1) * dp[i-1][j+1][prev_k]
        if j > 0: dp[i][j][k] += dp[i-1][j-1][prev_k]
        dp[i][j][k] %= MOD
    print(dp[N][0][K])

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  
    k = int(next(tokens))  
    solve(n, k)

if __name__ == '__main__':
    main()

Solution (Python):
import itertools
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N, K = list(map(int, sys.stdin.readline().split()))

if K % 2 == 1:
    print(0)
    exit()
if N == 1:
    if K == 0:
        print(1)
    else:
        print(0)
    exit()
if K == 0:
    print(1)
    exit()



dp = [[[0] * (K + 1) for _ in range(N)] for _ in range(N)]
dp[0][0][0] = 1
dp[0][1][2] = 1
for i, j, k in itertools.product(range(1, N), range(N - 1), range(K + 1)):
    if k - j * 2 < 0:
        continue
    
    
    
    dp[i][j][k] += dp[i - 1][j][k - j * 2] * 1
    
    
    
    
    dp[i][j][k] += dp[i - 1][j][k - j * 2] * (j * 2)
    
    
    
    dp[i][j][k] += dp[i - 1][j + 1][k - j * 2] * (j + 1) ** 2
    if j - 1 >= 0:
        
        
        dp[i][j][k] += dp[i - 1][j - 1][k - j * 2]

    dp[i][j][k] %= MOD
print(dp[-1][0][K])

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
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)]

sys.setrecursionlimit(1000000)
mod = 1000000007


def A():
    n = I()
    print(3*n**2)
    return


def B():
    n,d = LI()
    f = [1]*(n+2*d+2)
    ans = 0
    for i in range(n):
        if f[i]:
            for j in range(i,i+2*d+1):
                f[j] = 0
            ans += 1
    print(ans)
    return


def C():
    n = I()
    a = IR(n)
    mi = max(a)
    if a.count(mi) > 1:
        for i in range(n):
            print(mi)
    else:
        b = [a[i] for i in range(n)]
        b.sort()
        b = b[::-1]
        for i in range(n):
            if mi != a[i]:
                print(mi)
            else:
                print(b[1])

    return


def D():
    n = I()
    a = LI()
    b = [0]*(n+1)
    for i in range(1,n+1)[::-1]:
        j = 2*i
        k = 0
        while j <= n:
            k ^= b[j]
            j += i
        if a[i-1]^k:
            b[i] = 1
    ans = []
    for i in range(n+1):
        if b[i]:
            ans.append(i)
    print(len(ans))
    if ans:
        print(*ans)
    return


def E():
    n = I()
    a = IR(n)
    mi = []
    ans = 0
    for i in range(n):
        j = bisect.bisect_right(mi,-a[i])
        if j == len(mi):
            mi.append(-a[i])
        else:
            mi[j] = -a[i]
    print(len(mi))
    return


def F():
    n,K = LI()
    dp = [[[0]*(K+2500) for j in range(n+1)] for i in range(n+1)] 
    dp[0][0][0] = 1
    for i in range(n):
        for j in range(i+1):
            for k in range(K+1):
                
                nj = j
                dp[i+1][nj][k+2*nj] += dp[i][j][k]
                dp[i+1][nj][k+2*nj] %= mod
                
                nj = j+1
                dp[i+1][nj][k+2*nj] += dp[i][j][k]
                dp[i+1][nj][k+2*nj] %= mod
                
                nj = j
                x = j*2 
                dp[i+1][nj][k+2*nj] += dp[i][j][k]*x
                dp[i+1][nj][k+2*nj] %= mod
                
                nj = j-1
                x = j*j 
                dp[i+1][nj][k+2*nj] += dp[i][j][k]*x
                dp[i+1][nj][k+2*nj] %= mod
    print(dp[n][0][K])
    return


if __name__ == "__main__":
    F()

Solution (Python):
N, K = map(int, input().split())
MOD = 10**9 + 7
memo = {}
def dfs(i, a, b, k):
    key = (i, a, b, k)
    if key in memo:
        return memo[key]
    if i == N:
        if b > 0:
            memo[key] = 0
            return 0
        return k == K
    r = dfs(i+1, a, b, k+a+b) + dfs(i+1, a+1, b+1, k+a+b+2)
    if a > 0:
        r += dfs(i+1, a, b, k+a+b) * a
    if b > 0:
        r += dfs(i+1, a, b, k+a+b) * b
    if a > 0 < b:
        r += dfs(i+1, a-1, b-1, k+a+b-2) * (a * b)
    memo[key] = r = r % MOD
    return r
print(dfs(0, 0, 0, 0))