Artillery

시간 제한1초메모리 제한1024 MB

요약
$N$개의 대포를 한 번씩 발사할 때, 연속한 두 발의 위치 차이의 합이 최대가 되는 순열을 구하고, 그런 순열의 개수를 $10^9+7$로 나눈 나머지, 사전순 첫 번째 순열, $M$번째 순열을 출력한다.
난이도

어려움10점 중 8점

유형
조합론, 그리디, 수학, 정렬
정답자
아직 제출이 없습니다

문제

The good soldier Švejk, serving in the 14-th mounted artillery regiment, has reached České Budějovice. Unexpectedly, general Finck von Finckenstein arrives to inspect the regiment. Lieutenant Lukaš must line up NN cannons (all horse-drawn, of course) and fire each one exactly once.

Unfortunately, the shots scare the horses. The effect is worse when consecutive shots are fired from cannons close to each other. Therefore, Lieutenant Lukaš asks Švejk to devise a firing sequence where consecutive shots are fired from cannons that are as far from each other as possible. More precisely, the sum of the distances is to be maximized.

A firing sequence for NN cannons is a reordering PP of the numbers 1…N1 \dots N, where P_1P\_1 is the number of the cannon fired first, P_iP\_i the number of the cannon fired ii-th in the sequence, and P_NP\_N the number of the cannon fired last. The sum of distances for such a sequence is S=∣P_1−P_2∣+∣P_2−P_3∣+⋯+∣P_N−1−P_N∣S = |P\_1-P\_2| + |P\_2-P\_3| + \dots + |P\_{N-1}-P\_N|.

When listing sequences, they are orderd so that when the first i−1i-1 elements of two sequences PP and QQ match, but the ii-th elements differ, the sequence with the smaller ii-th element comes earlier in the list.

Lieutenant Lukaš knows that the favourite number of general Finck von Finckenstein is MM, and suspects the general is likely to request the cannons to be fired in the order of the sequence on the MM-th position in the list of possible sequences.

To help Švejk, write a program that computes

  • SS, the maximal possible sum of distances;
  • KK, the total number of firing sequences with the maximal sum;
  • the first sequence in the list of all sequences with the maximal sum;
  • the MM-th sequence in the list of all sequences with the maximal sum.

입력

\sis The only line of input contains two integers: NN, the number of cannons (2≤N≤1052 \le N \le 10^5), and MM, the favourite number of general Finck von Finckenstein (1≤M≤min⁡(1018,K)1 \le M \le \min(10^{18}, K)), where KK is the total number of sequences with the maximal sum of distances.

출력

The first line of output should contain SS, the maximal possible sum of distances when NN cannons are fired in some sequence, and K mod 1,000,000,007K \bmod 1\\,000\\,000\\,007, where KK is the total number of sequences with the sum SS. The second line should contain NN integers: the first sequence in the list of all sequences with the maximal sum. The third line should also contain NN integers: the MM-th sequence in the list of all sequences with the maximal sum.

예제1

  1. 예제 1

    입력
    5 3
    
    예상 출력
    11 8
    2 4 1 5 3
    3 1 5 2 4