#P2528. Permutation Inversions

    ID: 15798 Type: Default 1000ms 256MiB

Permutation Inversions

Permutation Inversions

Given a sequence of nn distinct items with parameters A1,A2,,AnA_1, A_2, \dots, A_n, an inversion pair is defined as a pair (i,j)(i,j) such that 1i<jn1 \le i < j \le n and Ai>AjA_i > A_j. In other words, the inversion count of a permutation A=(A1,A2,,An)A = (A_1, A_2, \dots, A_n) is

$$I(A)=\#\{(i,j)\mid 1\le iA_j\}. $$

Grant, a sorter at SORT company, is interested in two things given two integers nn and tt:

  1. How many permutations of the numbers 1,2,,n1,2,\dots,n have exactly tt inversions?
  2. What is the lexicographically smallest permutation among those with exactly tt inversions?

A permutation A=(A1,A2,,An)A=(A_1,A_2,\dots,A_n) is considered lexicographically smaller than B=(B1,B2,,Bn)B=(B_1,B_2,\dots,B_n) if there exists an index 1in1\le i\le n such that A1=B1,  A2=B2,  ,  Ai1=Bi1A_1=B_1,\; A_2=B_2,\; \dots,\; A_{i-1}=B_{i-1} and Ai<BiA_i<B_i.

It is guaranteed that 0tn(n1)20 \le t \le \frac{n(n-1)}{2}.

inputFormat

The input consists of a single line containing two integers nn and tt, separated by a space.

outputFormat

Output two lines:

  • The first line contains a single integer representing the total number of permutations of 1,2,,n1,2,\dots,n with exactly tt inversions.
  • The second line contains the lexicographically smallest permutation (as nn space-separated integers) among those with exactly tt inversions.

sample

3 0
1

1 2 3

</p>