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)

fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn main() {
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let n: usize = scan(tokens);
    let k: usize = scan(tokens);
    if k % 2 == 1 || k > n * n / 2 {
        println!("0");
        return;
    }
    let k = k / 2;
    let modulo: usize = 1_000_000_007;
    let mut dp: Vec<Vec<Vec<usize>>> = vec![vec![vec![0; k + 1]; n + 1]; 2];
    dp[0][0][0] = 1;
    for a in 1..n + 1 {
        for b in 0..n + 1 {
            for c in 0..k + 1 {
                let mut tmp: usize = 0;
                if b <= c {
                    if b != 0 {
                        tmp += dp[(a - 1) & 1][b - 1][c - b];
                    }
                    tmp += (2 * b + 1) * dp[(a - 1) & 1][b][c - b];
                    if b < n {
                        tmp += (b + 1) * (b + 1) * dp[(a - 1) & 1][b + 1][c - b];
                    }
                }
                dp[a & 1][b][c] = tmp % modulo;
            }
        }
    }
    println!("{}", dp[n & 1][0][k]);
}