#include using namespace std; #define st first #define nd second typedef long long ll; const int SIGMA = 26; const int MAXBUF = 103; 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); } } node* getNextEdge(node* cur, node* root, int a) { node* cp = cur; while(cur->next[a] == NULL) { cur = cur->prefix; if(cur == NULL) { cur = root; break; } } return cur->next[a]; } vector > matrix(MAXBUF,vector(MAXBUF)); int visited[MAXBUF+1]; void dfs(node* root, node* roott) { visited[root->num] = true; for(int i=0;iend == NULL) { matrix[root->num][ed->num]++; if(!visited[ed->num]) dfs(ed,roott); } } } 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 a