This page is still under construction.

Parts of this page are still being built. What you see may change.

Inversions

Interview

Time limit1sMemory limit128 MB

Summary
Count permutations of size n that have exactly k inversions, modulo 30011, using the Mahonian number recurrence with a sliding window over prefix sums.
Level

Medium6 of 10

Topics
Dynamic programming, Combinatorics, Prefix sum, Sliding window
Solved
No attempts yet

Problem

A sequence x1,x2,…,xnx_1, x_2, \dots, x_n of distinct integers is a permutation of size nn when 1≤xi≤n1 \le x_i \le n holds for every 1≤i≤n1 \le i \le n. For a permutation, an inversion is a pair of indices 1≤i<j≤n1 \le i < j \le n with xi>xjx_i > x_j.

Given nn and kk, count how many permutations of size nn have exactly kk inversions.

Input

A single line with two integers nn and kk (1≤n≤5001 \le n \le 500, 0≤k≤n(n−1)/20 \le k \le n(n-1)/2), separated by one space: the size of the permutation and the target number of inversions.

Output

Print one line with the number of permutations of size nn that have exactly kk inversions, taken modulo 3001130011.

Hint

The permutations of size 33 with 22 inversions are (2,3,1)(2, 3, 1) and (3,1,2)(3, 1, 2), so the answer for n=3n = 3, k=2k = 2 is 22.

Examples2

  1. Example 1

    Input
    3 2
    
    Expected output
    2
    
  2. Example 2

    Input
    4 3
    
    Expected output
    6