P26794 [AtCoder] Stick Combination
提高
题目描述

Problem Description

There are a total of $ N $ sticks, each with lengths $ 1, 3, 5, 7, ..., 2N-1 $.

You have been asked by a stick seller to glue the sticks together to make them of equal length for selling in the shop.

Output one way to glue the sticks such that at least two sticks remain after gluing, and all the remaining sticks are of equal length.

If such a gluing method does not exist, output impossible.

When multiple sticks are glued together, the length of the resulting stick is the sum of the lengths of the sticks used in the gluing. You cannot discard or cut the sticks.

Input Format

The input is given from the standard input in the following format:

$ N $

Output Format

If a gluing method satisfying the conditions in the problem statement exists, output the number of sticks remaining after gluing $ M $ on the first line, followed by $m + 1 (1 \leq m \leq M)$ lines, where the first element of each line is the number of sticks $ l_m $ to be glued to make the $ m $-th stick, and the same line contains the lengths $x_{m,i} (1 \leq i \leq l_m)$ of the sticks to be glued, separated by spaces.

If there are multiple combinations of gluing that satisfy the conditions, you may output any one of them.

If no such gluing method exists, output impossible.

  • $2 \leq M \leq N$
  • $1 \leq l_m \leq N$ $(1 \leq m \leq M)$
  • $\sum_{m}{l_m} = N$
  • $x_{m,i} \in \{1, 3, 5, ..., 2N-1\}$ $(1 \leq i \leq l_m)$
  • $ x_{m,i} $ are distinct.
  • $\sum_{i}{x_{1,i}} = \sum_{i}{x_{2,i}} = ... = \sum_{i}{x_{M,i}}$
  • All outputs should be integers.

$ M $ $ l_1 $ $ x_{1,1} $ $ x_{1,2} $ $ ... $ $ x_{1,l_1} $ $ l_2 $ $ x_{2,1} $ $ x_{2,2} $ $ ... $ $ x_{1,l_2} $ $ : $ $ l_M $ $ x_{M,1} $ $ x_{M,2} $ $ ... $ $ x_{M,l_M} $

Sample Input and Output

Sample Input #1

4

Sample Output #1

2
2 1 7
2 3 5

Sample Input #2

2

Sample Output #2

impossible

Sample Input #3

3

Sample Output #3

impossible

Notes/Hints

Constraints

  • All inputs are integers.
  • $2 \leq N \leq 10^5$

Sample Explanation 1

By dividing the sticks of lengths $ 1, 3, 5, 7 $ into $ 1, 7 $ and $ 3, 5 $ and gluing them respectively, you get two sticks of length $ 8 $, which satisfies the conditions.

Sample Explanation 2

No matter how you glue the two sticks of lengths $ 1 $ and $ 3 $, you cannot get at least two sticks of the same length.

Sample Explanation 3

With only three sticks of lengths $ 1, 3, 5 $, there is no gluing method that satisfies the conditions.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
4
样例输出
2 2 1 7 2 3 5