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 in C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(int i=s;i<t;i++)
typedef long long ll;
ll dp[55][55][55*55*2];
const ll mod=1e9+7;
void add(ll &a,ll b)
{
    a+=b;
    if(a>=mod)a-=mod;
}
int main()
{
    int n,k;scanf("%d%d",&n,&k);int tmp=n*n;
    dp[0][0][tmp]=1;
    rep(i,0,n)rep(j,0,i+1)rep(x,0,n*n*2+1)
    if(dp[i][j][x])
    {
        add(dp[i+1][j][x],dp[i][j][x]);
        add(dp[i+1][j][x],dp[i][j][x]*j%mod);
        add(dp[i+1][j+1][x-2*i-2],dp[i][j][x]);
        add(dp[i+1][j-1][x+2*i+2],dp[i][j][x]*j%mod*j%mod);
        add(dp[i+1][j][x],dp[i][j][x]*j%mod);
    }
    printf("%lld\n",dp[n][0][k+n*n]);
}