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: Wrong Answer)

#include <bits/stdc++.h>

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t n, k;
  std::cin >> n >> k;
  constexpr int64_t mod = 10000000007;

  std::vector<std::vector<std::vector<int64_t>>> dp(
      n + 1,
      std::vector<std::vector<int64_t>>(n + 1, std::vector<int64_t>(k + 1, 0)));

  dp[0][0][0] = 1;
  for (int64_t i = 0; i < n + 1; i++) {
    for (int64_t j = 0; j <= i; j++) {
      for (int64_t l = 0; l < k + 1; l++) {
        if (i + 1 <= n && j + 1 <= n && l + 2 * (j + 1) <= k) {
          dp[i + 1][j + 1][l + 2 * (j + 1)] += dp[i][j][l];
          dp[i + 1][j + 1][l + 2 * (j + 1)] %= mod;
        }
        if (i + 1 <= n && l + 2 * j <= k) {
          dp[i + 1][j][l + 2 * j] += dp[i][j][l];
          dp[i + 1][j][l + 2 * j] %= mod;
        }
        if (i + 1 <= n && l + 2 * j <= k) {
          dp[i + 1][j][l + 2 * j] += 2 * j * dp[i][j][l];
          dp[i + 1][j][l + 2 * j] %= mod;
        }
        if (i + 1 <= n && 0 <= j - 1 && l + 2 * (j - 1) <= k) {
          dp[i + 1][j - 1][l + 2 * (j - 1)] += j * j * dp[i][j][l];
          dp[i + 1][j - 1][l + 2 * (j - 1)] %= mod;
        }
        /*
        if (0 <= i - 1 && 0 <= l - 2 * j) {
          dp[i][j][l] += (2 * j + 1) * dp[i - 1][j][l - 2 * j];
          dp[i][j][l] %= mod;
          if (j + 1 <= n) {
            dp[i][j][l] += (j + 1) * (j + 1) * dp[i - 1][j + 1][l - 2 * j];
            dp[i][j][l] %= mod;
          }
          if (0 <= j - 1) {
            dp[i][j][l] += dp[i - 1][j - 1][l - 2 * j];
            dp[i][j][l] %= mod;
          }
        }
        */
      }
    }
  }

  std::cout << dp[n][0][k] << std::endl;
  return 0;
}