"Chaar Chawanni Ghode Pe..."

5

2 votes
Problem

The streets were filled with cheerings, "Chaar Chawanni Ghode Pe...". But it was not so peaceful everywhere...

In the aftermath of the abrogation of Article 370, the government introduced some very strict laws to curb the spread of hate speech. In particular certain K blasphemous words were banned and some new rules for the formation of words were put in place.

For simplicity assume that all english words are composed of lowercase and uppercase Latin letters in any order. In any legal word the banned words must not occur as a substring disregarding the case of the individual characters. To make things simple the banned words are specified with lowercase characters only. Hence, if "ab" is banned, then both "abCD" and "AbcD" are not legal. Morever, the number of lowercase characters should equal the number of uppercase characters in any legal word as they promote the idea of equality. 

Anand, being a Leftist for life, thought all these rules were non-sense. He found himself lost at legal words while chatting with this junior girlfriend from school. He began to wonder whether there are enough legal words or not. Hence find the number of possible legal words of length atmost N, as this value could be large find it modulo 109+7.

Input:

  • The first line contains one integer N.
  • The second line contains one integer K.
  • Next K lines each contain a banned word consisting of lowercase Latin letters only.

Ouput:

  • Ouput one integer the number of legal words modulo 109+7.

Constraints:

  • 1N50
  • 0K50
  • 1(length of each banned word)10
Time Limit: 1
Memory Limit: 256
Source Limit:
Editor Image

?