It is now a very difficult time now for Arif
as he is coming back to
After thinking for along time he remembers the different type of beads that the necklace had, he also remembers the length of the necklace but fails to remember the pattern of beads (The frequency of different types of beads and their ordering). Arif is very rich now and so he decides to buy a long string of beads from which he will be able to cut away any pattern of necklace. Help Arif to solve this problem, because, in solving problems related to his first love he is still very nervous and inefficient. Remember that the bead string ABBB and BBBA are not the same because the beads are not always symmetric. There are also some other reasons which are not worth mentioning here.
The input file contains several lines of input. Each line contains a string and an integer separated by a single space. The string contains different alpha numerals, which denote the different types of beads the necklace have. The length of this string is less than five. The next integer N (0<N<=20) denotes the length of the necklace or the number of beads of in the necklace.
For each line of input produce two lines of output. On the first line you will have to print the minimum length of the bead string that Arif will buy. If the length of the bead string is less than 10001 you will have to print the bead string on the next line. If its length is greater than 10000 then print the line “TOO LONG TO PRINT.” instead.
Warm-up Contest, Problem setter: Shahriar Manzoor)
“If you can give the right person proper recognition people will praise you.
But if you fail to give someone proper recognition, time will come
when you will badly need recognition from the one
you never wanted to recognize.”