Liza, after the hole affair, was pretty upset with Henry. In an effort to get him to think, she had him fill a barrel with several different buckets. The barrel had to be filled exactly to the top by whole (or is that hole?) bucket quantities. Henry, being lazy, kept thinking about it until he could do it in the fewest buckets possible.
Sample Input A: Sample Input B: Sample Input C: 17 20 36 1 7 19 2 5 9 4 3 5 5 1 2 1 Sample Output A: Sample Output B: Sample Output C: 4 4 4
Example, this is a square:
1, 2; 2, 3; 3, 4; 4, 1;;
For the square above, the answer is ``2''.
The basic idea behind RLE is to replace, say, 20 consecutive occurrences of the character `.', with the number 20 and a single `.'. This variant allows runs to be longer than one character. For example, the sequence abcabcabcabcabc should be converted into 0503abc. The first two characters, 05, are a pair of digits specifying how many times the pattern is repeated; the next two characters, 03, are the length of the repeated pattern, and that many characters following (abc) is the pattern to be repeated, itself.
Each compression saves a certain number of characters. The digits are not to be counted in considering the length of the compressed sequence. In the example above, 12 characters were saved. Each string to be compressed will probably consist of more than one repeated pattern. For example, the string abcdabcdabcdefefefefgggggg should turn into 0304abcd0402ef0601g.
When compressing a string, always start by compressing the repeated sequence that saves the most characters first, and then compress what's left over on the left, and on the right. For example, the string aabbaabbbbaabb should be compressed as 0201a0206bbaabb and not as 0204aabb0106bbaabb or 0204aabb0202bb0202aa0202bb. If more than one such sequence exists, pick the longer one. If more than one have the same length, pick the one further to the right.
If a string has no repeating sequences, output it with no digits in front.
You will receive a number of lines of text on standard input. These lines will not contain digits. You are to compress each one as described above, and write your answer to standard output. Use one line of output for each line of input.
abcdabcdabcdefefefefgggggg aabbaabbbbaabb bananananas fors fors aaaaa a a aaaaaa aaaaa a a aaaa
0304abcd0402ef0601g 0201a0206bbaabb ba0402nas0205 fors 0401a0302a 0601a 0501a0302 a0301a