#P10547. Restoring the Permutation

    ID: 12566 Type: Default 1000ms 256MiB

Restoring the Permutation

Restoring the Permutation

There are \( n \) cells arranged in a line, numbered \(1,2,\dots,n\). Initially, cell \(i\) contains a card with number \(i\). A jumbler then performs \( n \) swap operations; in each operation two distinct cells \( i \) and \( j \) are selected and the cards in these cells are swapped. After all \( n \) swaps, a permutation of the cards is obtained.

Now the player must restore the original order by swapping cards. Swapping the cards in cells \( i \) and \( j \) takes \( |i-j| \) units of time. The player will use an optimal strategy that minimizes the total restoration time. In any cycle of the permutation (with at least two elements) the minimum time required to fix that cycle is \( \max(S)-\min(S) \) where \( S \) is the set of indices in that cycle. (Note that a cycle of length 1 is already correctly placed and costs 0 time.)

Determine the number of final permutations (possible outcomes of the jumbler’s \( n \) swaps) for which the player can restore the original order in no more than \( m \) total time. Two permutations are considered different if at least one card is in a different cell.

inputFormat

The first line contains two integers \( n \) and \( m \), where \( n \) is the number of cells (and cards) and \( m \) is the maximum allowed total time for restoration.

outputFormat

Output a single integer: the number of final permutations such that the player can restore the order in at most \( m \) total time.

sample

1 0
1