#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); } } void addEdge(node* cur, node* root, int a) { node* cp = cur; while(cur->next[a] == NULL) { cur = cur->prefix; if(cur == NULL) { cur = root; break; } } cp->next[a] = cur->next[a]; } int visited[MAXBUF]; vector > matrix(MAXBUF,vector(MAXBUF)); void dfs(node* root, node* roott) { if(root->end != NULL) return; visited[root->num] = 1; for(int i=0;inext[i]->end != NULL) continue; matrix[root->num][root->next[i]->num]++; if(visited[root->next[i]->num] == 0) { dfs(root->next[i],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