CPython lite logoProblemsContests

H3. Bamboo Tablet Archive #3 Upsolve

This problem is non-standard

During the Han dynasty, astronomers meticulously recorded the coordinates of celestial bodies to predict the future and regulate calendar events important for agriculture and society. These data were passed from the central astronomy administration to the provinces to synchronize events and give accurate instructions for agricultural cycles and religious ceremonies. The problem is that data records at that time were kept on bamboo tablets, and the collected data could take up quite a lot of space. How to transport them… Your task is to archive the information collected by astronomers as efficiently as possible.

Keep in mind that:

  • The beginning of such a record was marked with the symbol K, which means a celestial body;
  • Ancient Chinese tracked up to 99 celestial bodies (encoded as 01, 02, 03, ..., 98, 99);
  • Chinese astronomers did not use modern coordinates but divided the celestial sphere into 28 sections, called 'lunar mansions'. The position of a celestial body was described as being in one of the 28 lunar mansions (01, ..., 28);
  • At that time, China used a complex calendar system in which each year was recorded by specifying one of the 10 Heavenly Stems and 12 Earthly Branches. The combination of Heavenly Stems and Earthly Branches uniquely determined the year (stems encoded as 01, ..., 10; branches 01, ..., 12);
  • The year consisted of 12 months of 29-30 days (months encoded as 01, ..., 12; days 01, ..., 30).

Example: The Moon was observed in the 14th lunar mansion in the year defined by the 6th Heavenly Stem and 12th Earthly Branch, in May on the 23rd date.

Record: K011406120523

Therefore, in this task, for each test your solution will run twice:

  • In the first run, your program receives input with the number 1 on the first line, the number n(1n105) on the second line, which is the number of records, and then n lines with the records themselves. As an output, you must produce a binary string. The records are given in lexicographical order.
  • In the second run, your program receives input with the number 2 on the first line, and on the second line, the binary string that your program output in the first run. As an output, you should print the number n and in the following n lines, output the records that were given in the first run.

In other words, you should implement encryption and decryption in one solution.

In this task, the length of the binary string output by your program should not exceed 2121212 characters.


Output

In this problem records are generated equitably at random.

The binary string that was output in the first run is shown for illustrative purposes only and may not have anything in common with the real solution.


Sample input 1

1
7
K112404110313
K120904070423
K260702060324
K360701040830
K422106090721
K712404040804
K932201121106

2
1010101010101010101010101010

Sample output 1

1010101010101010101010101010

7
K112404110313
K120904070423
K260702060324
K360701040830
K422106090721
K712404040804
K932201121106