#P1905. Balanced Goods Distribution

    ID: 15187 Type: Default 1000ms 256MiB

Balanced Goods Distribution

Balanced Goods Distribution

In the ancient port of Genoa, there are three kinds of goods — pottery, furniture and marble — with weights of 11, 22, and 33 units respectively. In total there are nn goods (where n=a+b+cn=a+b+c, with aa, bb, cc being the counts of pottery, furniture and marble respectively). There are also pp ships at Capua waiting to be loaded. Your task is to partition all the goods into pp piles subject to the following rules:

  1. In each pile, the weights (representing a good) arranged from bottom to top must be strictly decreasing. (For example, marble (weight 33) cannot be stacked on top of furniture or pottery.)

  2. The difference between the total weights of any two piles cannot exceed 33 units.

A valid solution always exists under the input constraints (note that since each pile can contain at most one of each type of goods, the maximum number of items in a pile is 33, and hence n3pn \le 3p). Output any one valid stacking scheme.

inputFormat

The input consists of a single line containing four integers separated by spaces:

  • a: the number of pottery items (each weighing 1 unit),
  • b: the number of furniture items (each weighing 2 units),
  • c: the number of marble items (each weighing 3 units),
  • p: the number of piles (ships).

It is guaranteed that a solution exists and that n=a+b+c3pn=a+b+c\le 3p.

outputFormat

The output should describe a valid distribution of goods into pp piles. The first line should contain pp integers separated by spaces, where each integer represents the total weight of one pile. This is followed by pp lines, each line describing one pile. For each pile, list the weights of goods from bottom to top (separated by a space). Note that each pile must follow the strictly decreasing rule and the maximum difference between the total weights of any two piles must not exceed 3.

sample

3 3 3 3
6 6 6

3 2 1 3 2 1 3 2 1

</p>