#include #include #include using namespace std; #define LL unsigned __int64 struct node { int cnt; struct node *fail; struct node *next[26]; struct node *jump[26]; }; node root[33]; int num; char str[10]; LL mod=10330176681277348905; void insert(char word[]) { int i=0; node *tmp=root; while(word[i]) { int b=word[i]-'a'; if(tmp->next[b]==NULL) { tmp->next[b]=root+num; memset(root+num,0,sizeof(struct node)); num++; } tmp=tmp->next[b]; i++; } tmp->cnt=1; } node *q[33]; int head,tail; void add_fail() { head=tail=0; q[tail++]=root; while(headfail; while(t!=NULL && t->next[i]==NULL) t=t->fail; if(x->next[i]!=NULL) { q[tail++]=x->next[i]; if(t==NULL) x->next[i]->fail=root; else { x->next[i]->fail=t->next[i]; if(t->next[i]->cnt) x->next[i]->cnt=1; } x->jump[i]=x->next[i]; } else { if(t==NULL) x->jump[i]=root; else x->jump[i]=t->next[i]; } } } } int m; int n; struct Mat { LL a[2*33][2*33]; void init() { int i,j; for(i=0;i<2*33;i++) for(j=0;j<2*33;j++) a[i][j]=0; } }; int len; Mat e; Mat mul(Mat a,Mat b) { Mat res; int i,j,k; for(i=0;i<2*len;i++) { for(j=0;j<2*len;j++) { res.a[i][j]=0; for(k=0;k<2*len;k++) { if(a.a[i][k]>0 && b.a[k][j]>0) { res.a[i][j]+=a.a[i][k]*b.a[k][j]; } } } } return res; } LL solve(Mat a,int k) { Mat b,ans=e; int i,j; b.init(); for(i=0;i