Word Game

Time Limit: 4000ms
Memory Limit: 32768KB
This problem will be judged on HDU. Original ID: 2657
64-bit integer IO format: %I64d      Java class name: Main

Description

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.

Input

The input contains several cases. Each case starts with two integer n and K. Then follows n lines, each line contain a string. 0 < n <= 8, 0 < K <= 200, each string contain between 1 and 20 characters. Input ends with a case n = 0 and K = 0.

Output

Each case print a line with an integer.

Sample Input

3 3
AAB
AAB
AAB
0 0

Sample Output

6

Source

Language: 
Theme: 
Share Code? 

Powered by NB231 | Current Style: .