If you have a circle consists of L characters. We can define one of them as 0th character, and then 1st, 2nd …… (L -1)th along the clockwise. A string beginning with the ith character can be get from this circle, let's call it p[i] (All of these string has a length of L). From 0 to L -1, if there exists exactly K positions i make p[i] as same as p[0], then we call it a magic word.
Give you n strings and a K. Please use all of these strings to creat a new string p. Tell me how many ways exists to construct a string p and make it a magic word.