Subway Lines X29412


Statement
 

pdf   zip

html

Ben Zynoulus lives in a city in Meashara. He travels around only by subway. Each subway line is a cycle, thus if you enter at station s1, you will reach s2, then s3, ..., sk, then you return to s1, then to s2, and so on.

Each subway line is unidirectional: you can go from s1 to s2, but not from s2 to s1. In some cases there might be another subway line which goes from s2 to s1; however, Ben has a rule that, after going from s1 to s2, he never goes back directly to s1.

As every subway user, Ben has a card to pay for his tickets, and this card notes the number of stations travelled so far, over all his lifetime. Now, Ben has a question: how many possible routes could he have taken, according to his rules? If there are two subway lines which go from s1 to s2, then he considers routes using them distinct.

Input

Each subway station has a code, which is a lowercase letter of the English alphabet.

The first line contains N (1 ≤ N ≤ 5), the number of subway routes, and L (1 ≤ L ≤ 30000000), the number of stations travelled so far. Each of the following N lines contains a description of one subway route, as a string. These are codes of consecutive stations of the given route.

Output

Output the number of possible routes modulo 1000007.

In this case Ben can travel either a-b-c-d-e-a-..., or e-d-c-b-a-e-... He cannot change between these two options, since he would break his rule. However, in the first case, he can change the subway line he is using after each station. This gives us 5 · (210+1) possible routes in total.

Public test cases
  • Input

    3 10
    abcde
    abcde
    edcba
    

    Output

    5125
    
  • Information
    Author
    Eryk Kopczynski
    Language
    English
    Official solutions
    Unknown. This problem is being checked.
    User solutions
    C++