#include using namespace std; #define st first #define nd second typedef long long ll; const int SIGMA = 26; const int MAXBUF = 205; inline int alpha(char c) {return c-'a';} struct node { node* prefix, *next[SIGMA]; const char *end; node* accept; node* get_accept() {return end ? this : accept;} int num = 0; void evaluate(int a, queue& Q) { if(next[a]) { next[a]->prefix = prefix->next[a]; next[a]->accept = next[a]->prefix->get_accept(); Q.push(next[a]); } else next[a] = prefix->next[a]; } }; node buf[MAXBUF]; int bufc; node* get_node() { for(int a=0;anext[a]) { root->next[a] = get_node(); } root = root->next[a]; } root->end = str; } void evaluate(node* root) { root->prefix = get_node(); for(int a=0;aprefix->next[a] = root; queue Q; Q.push(root); while(!Q.empty()) { node* cur = Q.front(); Q.pop(); for(int a=0;aevaluate(a,Q); } } vector > matrix(MAXBUF,vector(MAXBUF)); const ll MOD = 1e9+7; vector > mul(vector > a, vector > b) { vector > c(a.size(),vector(a.size())); for(int i=0;i > fme(vector > a, ll k) { if(k == 0) { for(int i=0;i> n >> m; vector vect(m); for(int i=0;i> a >> vect[i]; } sort(vect.begin(),vect.end()); vect.erase(unique(vect.begin(),vect.end()),vect.end()); sort(vect.begin(),vect.end(),[](const string&a, const string&b) {if(a.size() == b.size()) return aend == NULL) matrix[i][buf[i].next[a]->num]++; } } auto res = fme(matrix,n); ll v = 0; for(int i=0;i