Peephole Password
Legend has it that the ancient people of Yuezhou invented a way to store encrypted information by representing it as a sequence of decimal digits and engraving them in order along the edge of a fragile ceramic disk.
By chance, Xiao Bu obtained one such ceramic disk, but it was encased in a rotatable polarizing box (polarization is an optical phenomenon where only light waves vibrating in a specific direction can pass through the box). Through the polarizing box, Xiao Bu could only see 4 consecutive digits (consecutive along the circumference). To study the numerical information on the ceramic disk, Xiao Bu's team decided to open the box and remove the ceramic piece, but unfortunately, the ceramic piece shattered during the process.
Just as the team was feeling extremely discouraged, Xiao Bu suddenly remembered that he had once noted down some of the four-digit numbers he had seen in his notebook. However, because the polarizing box was rotatable, the positions and order of these four-digit numbers were no longer distinguishable. Xiao Bu decided to recover the original data as much as possible by analyzing these recorded four-digit numbers. Thus, Xiao Bu came to you.
Your task is to recover the original data on the disk. You will be given $N$ four-digit numbers recorded by Xiao Bu, and your task is to find the shortest possible circular sequence of digits that contains every four-digit number recorded by Xiao Bu.
Input
This is an answer-submission problem; all input files password*.in are already in the directory.
The first line of the input file contains the number of four-digit numbers $N$. The next $N$ lines each contain a four-digit number (which may contain leading zeros).
Output
The output file password*.out should contain two lines. The first line contains an integer $M$, representing the length of the circular sequence you found.
The second line contains $M$ digits (with no spaces between adjacent digits, see example), representing the circular sequence.
Examples
Input 1
3 1234 2345 1234
Output 1
5 34512
Note
The output 12345, 23451, 45123, or 51234 are all acceptable.
Subtasks
Each test case is scored individually. For each test case, if your output file is invalid (e.g., incorrect file format, the solution does not meet the requirements), you will receive 0 points for that test case. Otherwise, let $ans$ be the length of your output answer. For different test cases, we have 9 scoring constants $c1 \le c2 \le c3 \le c4 \le c5 \le c6 \le c7 \le c8 \le c9$. Your score for the test case is determined as follows:
- If $ans > 4N$, you get 0 points.
- If $ans \le 4N$, you get 1 point.
- If $ans \le c9$, you get 2 points.
- If $ans \le c8$, you get 3 points.
- If $ans \le c7$, you get 4 points.
- If $ans \le c6$, you get 5 points.
- If $ans \le c5$, you get 6 points.
- If $ans \le c4$, you get 7 points.
- If $ans \le c3$, you get 8 points.
- If $ans \le c2$, you get 9 points.
- If $ans = c1$, you get 10 points.
- If $ans < c1$, you get 12 points.
If multiple conditions are met, the highest score is taken as the final score.
Interaction
You can use the checker program to check your output. The format is:
./checker TestNo
where TestNo is the test case number. For example, if you have already obtained the output password5.out for data 5, you can use the command ./checker 5 to test whether your output is valid.
Note
Please keep the input files *.in and your output *.out safe and back them up in time to avoid accidental deletion.