#include using namespace std; #define modulo 998244353 #define mod(mod_x) ((((long long)mod_x+modulo))%modulo) #define Inf 1000000000000 template struct trie{ T init_value; struct node{ vector next; T v; T sum; int depth; node(int wordSize,T iv,int d){ next.resize(wordSize,-1); v = iv; sum = iv; depth = d; } int link=-1; }; vector nodes; int wordSize; trie(int sz,T iv){ init_value = iv; wordSize = sz; nodes.push_back(node(wordSize,init_value,0)); } void add(string &S,T x,int cPos=0,int cNode=0){ if(cPos==S.size()){ nodes[cNode].v = func(nodes[cNode].v,x); return; } int c = encode(S[cPos]); if(nodes[cNode].next[c]==-1){ nodes[cNode].next[c] = nodes.size(); nodes.push_back(node(wordSize,init_value,nodes[cNode].depth+1)); } int nextNode = nodes[cNode].next[c]; add(S,x,cPos+1,nextNode); } void set_link(){ nodes[0].link = 0; queue Q; Q.push(0); while(Q.size()!=0){ int now = Q.front(); Q.pop(); nodes[now].v = func(nodes[now].v,nodes[nodes[now].link].v); nodes[now].sum = func(nodes[now].sum,nodes[now].v); for(int i=0;i>S; int M; cin>>M; trie T(26,0); for(int i=0;i>s; T.add(s,1); } T.set_link(); long long ans = T.query(S); cout<