This page is still under construction.

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

Inv

Time limit2sMemory limit512 MB

Summary
Count involutions of n elements with exactly k inversions and report the count modulo 2.
Level

Hard8 of 10

Topics
Combinatorics, Dynamic programming, Math, Bit manipulation
Solved
No attempts yet

Problem

A permutation pp on nn elements is an involution if p(p(i))=ip(p(i)) = i for each i=1,2,…,ni = 1, 2, \dots, n. Your task is to compute the number of involutions on nn elements with kk inversions. The answer can be large, so print only the parity of this number.

Input

The first line contains two space-separated integers: nn (1≤n≤5001 \le n \le 500), the length of the involution, and kk (0≤k≤n(n−1)20 \le k \le \frac{n(n-1)}{2}), the number of inversions.

Output

Print a single number (00 or 11): the number of involutions on nn elements with exactly kk inversions, taken modulo 22.

Hint

In the first sample, there are 33 such involutions.

Examples2

  1. Example 1

    Input
    4 1
    
    Expected output
    1
    
  2. Example 2

    Input
    10 21
    
    Expected output
    0