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 Rust (1.15.1) (judge verdict: Accepted)

use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

const MOD: usize = 1e+9 as usize + 7;
fn main() {
    let n = read::<usize>();
    let k = read::<usize>();
    let mut dp = vec![vec![vec![0; k + 1]; n + 1]; n + 1];
    dp[0][0][0] = 1;
    for depth in 0..n {
        for rest in 0..n {
            for value in 0..k + 1 {
                let ndepth = depth + 1;
                // nop
                let nrest = rest + 1;
                let nvalue = value + (rest + 1) * 2;
                if nvalue <= k && nrest <= n {
                    dp[ndepth][nrest][nvalue] =
                        (dp[ndepth][nrest][nvalue] + dp[depth][rest][value]) % MOD;
                }
                // use one, use self
                let nrest = rest;
                let nvalue = value + rest * 2;
                if nvalue <= k {
                    let cnt = 1 + 2 * rest;
                    dp[ndepth][nrest][nvalue] =
                        (dp[ndepth][nrest][nvalue] + cnt * dp[depth][rest][value]) % MOD;
                }
                // use both
                if rest > 0 {
                    let nrest = rest - 1;
                    let nvalue = value + (rest - 1) * 2;
                    let cnt = rest * rest;
                    if nvalue <= k {
                        dp[ndepth][nrest][nvalue] =
                            (dp[ndepth][nrest][nvalue] + cnt * dp[depth][rest][value]) % MOD;
                    }
                }
            }
        }
    }
    println!("{}", dp[n][0][k]);
}