cho.sh
Notes
Loading...

Nonlinear Sequences

Time limit

2s

Memory limit

128 MB

Problem

Three distinct numbers s1, s2, and s3 in this order are called a linear sequence if s2 - s1 = s3 - s2 and s1 < s2 < s3.

You are given the length L of a natural-number sequence and the maximum possible value M of its elements. The constraints are 4 <= L <= 13 and L < M <= 35. Consider every increasing sequence of length L whose elements are integers from 1 to M, inclusive, and in which no three elements form a linear sequence.

Print up to the first three valid sequences in lexicographic order. Lexicographic order compares two sequences from the front, and the sequence with the smaller first differing element comes first. On the last line, print the total number of valid sequences.

Input

The single input line contains two integers L and M.

Output

On the first up to three lines, print the lexicographically smallest valid sequences, one sequence per line. Separate adjacent elements in a sequence with a space.

On the last line, print the total number of valid sequences. The input is chosen so that this value is at most 2^31 - 1.