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



Sample input:
3 2


Sample output:
2

Submission status: Wrong Answer

Solution code:
import numpy as np
n, k = map(int, input().split())
m = n**2
mod = 10**9+7
dp = np.zeros((n+1, n+1, m+1), dtype=np.int64)
dp[0,0,0] = 1
for i in range(1, n+1):
  for j in range(i+1):
    dp[i,j,2*j:] = (2*j+1)*dp[i-1,j,:m+1-2*j]
    if j+1 <= i-1:
      dp[i,j,2*j:] += (j+1)*(j+1)*dp[i-1,j+1,:m+1-2*j]
    if j:
      dp[i,j,2*j:] += dp[i-1,j-1,:m+1-2*j]
ans = dp[n,0,k]%mod
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

N, K = map(int,input().split())
MOD = 10**9+7

# dp[i][j][k]:
# ウサギ1~i, カメ1~i (うちj個は相手が未定)まで見ていて，
# 確定している奇妙さがkであるような場合の数
dp = np.zeros((55,55,55*55), dtype='int64')
dp[0][0][0] = 1

for i in range(N+1):
    for j in range(N+1):
        for k in range(N+1):
            if k-2*j < 0 or i-1 < 0: continue

            dp[i][j][k] += (2*j+1) * dp[i-1][j][k-2*j] % MOD
            dp[i][j][k] %= MOD

            dp[i][j][k] += (j+1)*(j+1)*dp[i-1][j+1][k-2*j] % MOD
            dp[i][j][k] %= MOD

            if j > 0:
                dp[i][j][k] += dp[i-1][j-1][k-2*j]
                dp[i][j][k] %= MOD
            
            

print(dp[N][0][K])

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
if k==1:print(0)
else:print(1)

Submission status: Wrong Answer

Solution code:
MOD=10**9+7
n,k=map(int,input().split())

if k%2==1:
  print(0)
elif n%2==0:
  if k>n**2//2:
    print(0)
  else:    
    print(-1)
else:
  if k>(n**2-1)//2:
    print(0)
  else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

MOD = 10**9 + 7

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

# 左からの流入量、コスト
L = N*(N-1)//2+1
dp = np.zeros((N,L),dtype=np.int64)
dp[0,0] = 1

for _ in range(1,N+1):
    prev = dp
    dp = np.zeros_like(prev)
    for n in range(N):
        # 自身を不動点にしてそのまま左右に流す
        dp[n,n:] += prev[n,:L-n]
        # 左からのものを採用、自身は左に流す
        if n > 0: dp[n-1,n-1:] += prev[n,:L-n+1] * n
        # 左からのものを採用、自身は右に流す
        dp[n,n:] += prev[n,:L-n] * n
        # 右からのものを採用、自身は左に流す
        dp[n,n:] += prev[n,:L-n] * n
        # 右からのものを採用、自身は右に流す
        if n+1 < N: dp[n+1,n+1:] += prev[n,:L-n-1] * (n+1)

x = dp[0]
if K&1:
    answer = 0
elif K//2 < L:
    answer = x[K//2]
else:
    answer = 0
print(answer)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
dp = {}

dp[(0, 0, 0)] = 1

def perm(i, j, k):
  if (i, j, k) in dp:
    return dp[(i, j, k)]
  
  if i == 0 and (j is not 0 or k is not 0):
    return 0
  
  if i < 0 or j < 0 or k < 0 or i < j:
    return 0
  
  dp[(i, j, k)] = ((j+j+1)*perm(i-1, j, k-2*j)\
                + (j+1)*(j+1)*perm(i-1, j+1, k-2*j)\
                +  1*perm(i-1, j-1, k-2*j))%int(10e9+7)
  return dp[(i, j, k)]

print(perm(n, 0, k))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
dp = {}

dp[(0, 0, 0)] = 1

def perm(i, j, k):
  if (i, j, k) in dp:
    return dp[(i, j, k)]
  
  if i < 0 or j < 0 or k < 0 or i < j:
    return 0
  
  dp[(i, j, k)] = ((j+j+1)*perm(i-1, j, k-2*j)\
                + (j+1)*(j+1)*perm(i-1, j+1, k-2*j)\
                +  1*perm(i-1, j-1, k-2*j))%int(10e9+7)
  return dp[(i, j, k)]

print(perm(n, 0, k))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
dp = {}

dp[(0, 0, 0)] = 1

def perm(i, j, k):
  if (i, j, k) in dp:
    return dp[(i, j, k)]
  
  if i < 0 or j < 0 or k < 0:
    return 0
  
  dp[(i, j, k)] = ((j+j+1)*perm(i-1, j, k-2*j)\
                + (j+1)*(j+1)*perm(i-1, j+1, k-2*j)\
                +  1*perm(i-1, j-1, k-2*j))%int(10e9+7)
  return dp[(i, j, k)]

print(perm(n, 0, k))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
dp = {}

dp[(0, 0, 0)] = 1
dp[(0, 1, 2)] = 1

def perm(i, j, k):
  if i < 0 or j < 0 or k < 0:
    return 0
  
  if (i, j, k) in dp:
    return dp[(i, j, k)]
  else:
    dp[(i, j, k)] = ((j+j+1)*perm(i-1, j, k-2*j)\
                  + (j+1)*(j+1)*perm(i-1, j+1, k-2*j)\
                  +  1*perm(i-1, j-1, k-2*j))%int(10e9+7)
    return dp[(i, j, k)]

print(perm(n-1, 0, k))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
dp = {}

dp[(0, 0, 0)] = 1
dp[(0, 1, 2)] = 1

def perm(i, j, k):
#   print(i, j, k)
  if i < 0 or j < 0 or k < 0:
    return 0
  
  if (i, j, k) in dp:
    return dp[(i, j, k)]
  else:
    dp[(i, j, k)] = (j+j+1)*perm(i-1, j, k-2*j)\
                  + (j+1)*(j+1)*perm(i-1, j+1, k-2*j)\
                  +  1*perm(i-1, j-1, k-2*j)
    return dp[(i, j, k)]

print(perm(n-1, 0, k))

Submission status: Wrong Answer

Solution code:
def main():

    """ convenient functions
    # for i, a in enumerate(iterable)
    # q, mod = divmod(a, b)
    # divmod(x, y) returns the tuple (x//y, x%y)
    # Higher-order function: reduce(operator.mul, xyz_count, 1)
    # manage median(s) using two heapq https://atcoder.jp/contests/abc127/tasks/abc127_f
    """

    """convenient decorator
    # @functools.lru_cache():
    # to facilitate use of recursive function
        # ex:
        # from functools import lru_cache
        # import sys
        # sys.setrecursionlimit(10**9)
        # @lru_cache(maxsize=None)
        # def fib(n):
        #     if n < 2:
        #         return n
        #     return fib(n-1) + fib(n-2)
        # print(fib(1000))
    """
    
    # import numpy as np
    import sys
    sys.setrecursionlimit(10**7)
    from itertools import accumulate, combinations, permutations, product # https://docs.python.org/ja/3/library/itertools.html
    # accumulate() returns iterator! to get list: list(accumulate())
    from math import factorial, ceil, floor, sqrt
    def factorize(n):
        """return the factors of the Arg and count of each factor
        
        Args:
            n (long): number to be resolved into factors
        
        Returns:
            list of tuples: factorize(220) returns [(2, 2), (5, 1), (11, 1)]
        """
        fct = []  # prime factor
        b, e = 2, 0  # base, exponent
        while b * b <= n:
            while n % b == 0:
                n = n // b
                e = e + 1
            if e > 0:
                fct.append((b, e))
            b, e = b + 1, 0
        if n > 1:
            fct.append((n, 1))
        return fct
    def combinations_count(n, r):
        """Return the number of selecting r pieces of items from n kinds of items.
        
        Args:
            n (long): number
            r (long): number
        
        Raises:
            Exception: not defined when n or r is negative
        
        Returns:
            long: number
        """
        # TODO: How should I do when n - r is negative?
        if n < 0 or r < 0:
            raise Exception('combinations_count(n, r) not defined when n or r is negative')
        if n - r < r: r = n - r
        if r < 0: return 0
        if r == 0: return 1
        if r == 1: return n
        numerator = [n - r + k + 1 for k in range(r)]
        denominator = [k + 1 for k in range(r)]
        for p in range(2,r+1):
            pivot = denominator[p - 1]
            if pivot > 1:
                offset = (n - r) % p
                for k in range(p-1,r,p):
                    numerator[k - offset] /= pivot
                    denominator[k] /= pivot
        result = 1
        for k in range(r):
            if numerator[k] > 1:
                result *= int(numerator[k])
        return result
    def combinations_with_replacement_count(n, r):
        """Return the number of selecting r pieces of items from n kinds of items allowing individual elements to be repeated more than once.
        
        Args:
            n (long): number
            r (long): number
        
        Raises:
            Exception: not defined when n or r is negative
        
        Returns:
            long: number
        """
        if n < 0 or r < 0:
            raise Exception('combinations_with_replacement_count(n, r) not defined when n or r is negative')
        elif n == 0:
            return 1
        else:
            return combinations_count(n + r - 1, r)
    from bisect import bisect_left, bisect_right
    from collections import deque, Counter, defaultdict # https://docs.python.org/ja/3/library/collections.html#collections.deque
    from heapq import heapify, heappop, heappush, heappushpop, heapreplace,nlargest,nsmallest # https://docs.python.org/ja/3/library/heapq.html
    from copy import deepcopy, copy # https://docs.python.org/ja/3/library/copy.html
    import operator
    from operator import itemgetter
    # ex1: List.sort(key=itemgetter(1))
    # ex2: sorted(tuples, key=itemgetter(1,2))
    from functools import reduce, lru_cache
    def chmin(x, y):
        """change minimum
        if x > y, x = y and return (x, True).
        convenient when solving problems of dp[i]
        
        Args:
            x (long): current minimum value
            y (long): potential minimum value
        
        Returns:
            (x, bool): (x, True) when updated, else (x, False)
        """
        if x > y:
            x = y
            return (x, True)
        else:
            return (x, False)
    def chmax(x, y):
        """change maximum
        if x < y, x = y and return (x, True).
        convenient when solving problems of dp[i]
        
        Args:
            x (long): current maximum value
            y (long): potential maximum value
        
        Returns:
            (x, bool): (x, True) when updated, else (x, False)
        """
        if x < y:
            x = y
            return (x, True)
        else:
            return (x, False)

    from fractions import gcd # Deprecated since version 3.5: Use math.gcd() instead.
    def gcds(numbers):
        return reduce(gcd, numbers)
    def lcm(x, y):
        return (x * y) // gcd(x, y)
    def lcms(numbers):
        return reduce(lcm, numbers, 1)

    # first create factorial_list
    # fac_list = mod_factorial_list(n)
    INF = 10 ** 18
    MOD = 10 ** 9 + 7
    modpow = lambda a, n, p = MOD: pow(a, n, p) # Recursive function in python is slow!
    def modinv(a, p = MOD):
        # evaluate reciprocal using Fermat's little theorem:
        # a**(p-1) is identical to 1 (mod p) when a and p is coprime
        return modpow(a, p-2, p)
    def modinv_list(n, p = MOD):
        if n <= 1:
            return [0,1][:n+1]
        else:
            inv_t = [0,1]
            for i in range(2, n+1):
                inv_t += [inv_t[p % i] * (p - int(p / i)) % p]
            return inv_t
    def modfactorial_list(n, p = MOD):
        if n == 0:
            return [1]
        else:
            l = [0] * (n+1)
            tmp = 1
            for i in range(1, n+1):
                tmp = tmp * i % p
                l[i] = tmp
            return l
    def modcomb(n, k, fac_list = [], p = MOD):
        # fac_list = modfactorial_list(100)
        # print(modcomb(100, 5, modfactorial_list(100)))
        from math import factorial
        if n < 0 or k < 0 or n < k: return 0
        if n == 0 or k == 0: return 1
        if len(fac_list) <= n:
            a = factorial(n) % p
            b = factorial(k) % p
            c = factorial(n-k) % p
        else:
            a = fac_list[n]
            b = fac_list[k]
            c = fac_list[n-k]
        return (a * modpow(b, p-2, p) * modpow(c, p-2, p)) % p
    def modadd(a, b, p = MOD):
        return (a + b) % MOD
    def modsub(a, b, p = MOD):
        return (a - b) % p
    def modmul(a, b, p = MOD):
        return ((a % p) * (b % p)) % p
    def moddiv(a, b, p = MOD):
        return modmul(a, modpow(b, p-2, p))

    """ initialize variables and set inputs
    # initialize variables
        # to initialize list, use [0] * n
        # to initialize two dimentional array, use [[0] * N for _ in range(N)]
    # set inputs
        # open(0).read() is a convenient method:
        # ex) n, m, *x = map(int, open(0).read().split())
        #     min(x[::2]) - max(x[1::2])
        # ex2) *x, = map(int, open(0).read().split())
        #     don't forget to add comma after *x if only one variable is used
    # preprocessing
        # transpose = [x for x in zip(*data)]
        # ex) [[1, 2, 3], [4, 5, 6], [7, 8, 9]] => [(1, 4, 7), (2, 5, 8), (3, 6, 9)]
        # flat = [flatten for inner in data for flatten in inner]
        # ex) [[1, 2, 3], [4, 5, 6], [7, 8, 9]] => [1, 2, 3, 4, 5, 6, 7, 8, 9]
    # calculate and output
        # output pattern
        # ex1) print(*l) => when l = [2, 5, 6], printed 2 5 6
    """

    # functions used
    r = lambda: sys.stdin.readline().strip()
    r_int = lambda: int(r())
    R = lambda: list(map(int, r().split()))
    Rmap = lambda: map(int, r().split())
    Rfloat = lambda: list(map(float, r().split()))
    Rtuple = lambda: tuple(map(int, r().split()))

    """ how to treat input
    # single int: int(r())
    # single string: r()
    # single float: float(r())
    # line int: R()
    # line string: r().split()
    # line (str, int, int): [j if i == 0 else int(j) for i, j in enumerate(r().split())]
    # lines int: [R() for _ in range(n)]
    """

    if __name__ != '__main__':
        # for test
        sys.stdin = open('sample.txt')

    # ----------------------------------
    # main

    N, K = R()
    dp = [[[0]*3100 for _ in range(51)] for _ in range(51)]
    dp[0][0][0] = 1
    for i, rest, k in product(range(N), range(N), range(K+1)):
        dp[i+1][rest+1][k+2*rest+2] += dp[i][rest][k]
        if rest:
            dp[i+1][rest][k+2*rest] += dp[i][rest][k] * rest
            dp[i+1][rest][k+2*rest] += dp[i][rest][k] * rest
        dp[i+1][rest][k+2*rest] += dp[i][rest][k]
        if rest:
            dp[i+1][rest-1][k+2*rest-2] += dp[i][rest][k] * rest * rest
    print(dp[N][0][K])
    
    
    # end of main
    # ----------------------------------

    """memo: how to use defaultdict of list
    # initialize
    Dic = defaultdict(list)
    # append / extend
    Dic[x].append(y)
    # for
    for k, v in Dic.items():
    """

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
MOD = 10**9 + 7
n, oddness = [int(item) for item in input().split()]
# Oddness must be even
if oddness % 2 ==  1:
    print(0)
    exit()
oddness //= 2
max_oddness = 1300 + n
max_pending = n//2 + 2

dp = [[[0] * (max_oddness) for _ in range(max_pending)] for _ in range(n)]
dp[0][0][0] = 1
dp[0][1][1] = 1
k_itr = [item for item in range(1300)]
for i in range(1, n):
    for j in range(min(i+1, n//2)):
        for k in range(min(n*n, oddness+1)):
            dp_ijk = dp[i-1][j][k]
            # Oddness increase by num of pending item
            # Connect in line or Choose 1 from pending items
            dp[i][j][k+j] += dp_ijk * (1 + j*2)
            # dp[i][j][k+j] %= MOD
            # Choose 2 from pending items
            if j > 0:
                dp[i][j-1][k+j-1] += dp_ijk * j*j
                dp[i][j-1][k+j-1] %= MOD 
            # Do nothing 
            dp[i][j+1][k+j+1] += dp_ijk 
            # dp[i][j+1][k+j+1] %= MOD 

print(dp[n-1][0][oddness] % MOD)

Submission status: Wrong Answer

Solution code:
MOD = 10**9 + 7
n, oddness = [int(item) for item in input().split()]
oddness //= 2
max_oddness = n*n + n
max_pending = n + 1

dp = [[[0] * (max_oddness) for _ in range(max_pending)] for _ in range(n)]
oddness_itr = [item for item in range(n*n)]
for i in range(n):
    if i == 0:
        dp[0][0][0] = 1
        dp[0][1][1] = 1
        continue
    for j in range(i+1):
        for k in oddness_itr:
            # Connect in line
            # Oddness increase by num of pending item
            dp[i][j][k+j] += dp[i-1][j][k]
            # Choose 1 from pending
            dp[i][j][k+j] += dp[i-1][j][k] * j*2 
            dp[i][j][k+j] %= MOD
            # Choose 2 from pending
            if j > 0:
                dp[i][j-1][k+j-1] += dp[i-1][j][k] * j*j
                dp[i][j-1][k+j-1] %= MOD 
            # Do nothing 
            dp[i][j+1][k+j+1] += dp[i-1][j][k] 
            dp[i][j+1][k+j+1] %= MOD 

print(dp[n-1][0][oddness])

Submission status: Wrong Answer

Solution code:
import numpy as np
mod = 10 **9 + 7

n, k = map(int, input().split())
if k % 2:
    print(0)
    exit(0)
k = k // 2
a = np.zeros((n, k + 1), dtype=np.int64)
a[0, 0] = 1
for i in range(1, n):
    for j in range(i + 1):
        if j > k:
            break;
        a[i, j:k + 1] += a[i - 1, :k - j + 1]
    a[i] %= mod
print(a[n - 1, k])

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
m = 1000000007

dp = [[[0] * (K+2*N+1) for _ in range(N+1)] for _ in range(N+1)]

dp[0][0][0] = 1
for i in range(0, N):
  for j in range(0, i+1):
    for k in range(0, K+1):
      dp[i+1][j+1][k+2*(j+1)] = dp[i+1][j+1][k+2*(j+1)] + dp[i][j][k] % m
      dp[i+1][j][k+2*j] = dp[i+1][j][k+2*j] + dp[i][j][k] % m
      dp[i+1][j][k+2*j] = dp[i+1][j][k+2*j] + 2*j * dp[i][j][k] % m
      if j > 0:
      	dp[i+1][j-1][k+2*(j-1)] = dp[i+1][j-1][k+2*(j-1)] + j*j * dp[i][j][k] % m
print(dp[N][0][K])

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
m = 1e9+7

dp = [[[0] * (K+2*N+1) for _ in range(N+1)] for _ in range(N+1)]

dp[0][0][0] = 1
for i in range(0, N):
  for j in range(0, i+1):
    for k in range(0, K+1):
      dp[i+1][j+1][k+2*(j+1)] = dp[i+1][j+1][k+2*(j+1)] + dp[i][j][k] % m
      dp[i+1][j][k+2*j] = dp[i+1][j][k+2*j] + dp[i][j][k] % m
      dp[i+1][j][k+2*j] = dp[i+1][j][k+2*j] + 2*j * dp[i][j][k] % m
      if j > 0:
      	dp[i+1][j-1][k+2*(j-1)] = dp[i+1][j-1][k+2*(j-1)] + j*j * dp[i][j][k] % m
print(int(dp[N][0][K]))

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
m = 1e9+7

dp = [[[0] * (K+2*N+1) for _ in range(N+1)] for _ in range(N+1)]

dp[0][0][0] = 1
for i in range(0, N):
  for j in range(0, i+1):
    for k in range(0, K+1):
      dp[i+1][j+1][k+2*(j+1)] += dp[i][j][k] % m
      dp[i+1][j][k+2*j] += dp[i][j][k] % m
      dp[i+1][j][k+2*j] += 2*j * dp[i][j][k] % m
      if j > 0:
      	dp[i+1][j-1][k+2*(j-1)] += j*j * dp[i][j][k] % m
print(int(dp[N][0][K]))

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
m = 1e9+7

dp = [[[0] * (K+2*N) for _ in range(N+1)] for _ in range(N+1)]

dp[0][0][0] = 1
for i in range(0, N):
  for j in range(0, i+1):
    for k in range(0, K+1):
      dp[i+1][j+1][k+2*j] += dp[i][j][k] % m
      dp[i+1][j][k+2*j] += dp[i][j][k] % m
      dp[i+1][j][k+2*j] += 2*j * dp[i][j][k] % m
      if j > 0:
      	dp[i+1][j-1][k+2*j] += j*j * dp[i][j][k] % m
print(int(dp[N][0][K]))

Submission status: Wrong Answer

Solution code:
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
import sys
from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; ansli = []; tmpli = []; candili = []
eps = 1.0 / 10 ** 10; mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]; ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]; ddn9 = ddn + [(0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]#WideIntPoint
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]#HeightString
def mi(n): return [wi() for _ in range(n)]#MatrixInt
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]

n, k = wi()

mod = 10 ** 9 + 7
MAX_N = 3 * 10 ** 5 + 100
factorial = [1] * MAX_N
#事前に階上テーブルを用意
def calc_factorial():
    for i in range(1, MAX_N):
        factorial[i] = i * factorial[i - 1] % mod

def comb(n, k):
    a = factorial[n] % mod
    b = (factorial[k] * factorial[n - k]) % mod
    b_ = pow(b, mod - 2, mod)
    return (a * b_) % mod


# 階乗を用意
calc_factorial()

c = comb(k + n - 1, n - 1)

if k % 2 != 0:
    print(0)
else:
    print(c // 3)

Submission status: Wrong Answer

Solution code:
def nsum(N):
    t=(N+2)//2
    return 2*(-t+n+1)*(t-1)
mod=10**9+7
MAX_N=50
Fact=[0 for i in range(MAX_N+1)]
Fact[0]=1
for i in range(MAX_N):
    Fact[i+1]=(i+1)*Fact[i]
    Fact[i+1]%=mod
n,k=map(int,input().split())
dp=[[0 for q in range(n*n+1)] for p in range(n+1)]
dp[1][0]=1
for p in range(2,n+1):
    for q in range(nsum(p)):
        for r in range(q+1):
            #r,q-r
            dp[p][q]+=dp[p-1][r]*dp[p-1][q-r]
            dp[p][q]%=mod
    dp[p][nsum(p)]=(Fact[p//2]*p**(p%2))%mod
print(dp[n][k])

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


n, t = li()
MOD = 10**9 + 7

mx = n*(n-1) + 1

if t%2:
    print(0)

else:
    dp = [[0]*mx for _ in range(n+1)]
    dp[0][0] = 1
    jmax = 0

    for i in range(n):
        jmax += (n-i-1)
        for j in range(jmax+1):
            for k in range(n-i):
                dp[i+1][j+k] += dp[i][j]
                dp[i+1][j+k] %= MOD

    print(dp[n][t//2] % MOD)