#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include typedef long long ll; using namespace std; #define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl; #define mod 1000000007 //1e9+7(prime number) #define INF 1000000000 //1e9 #define LLINF 2000000000000000000LL //2e18 #define SIZE 100010 /* Aho Corasick */ struct ACNode{ int val; ACNode *next[26], *failure; ACNode():val(0) { memset(next,0,sizeof(next)); } void insert(char *s){ if(!*s){ val++; return; } int al = *s-'A'; if(next[al]==NULL) next[al] = new ACNode; next[al]->insert(s+1); } ACNode *nextNode(char c){ int al = c - 'A'; if (next[al]) return next[al]; return failure == this ? this : failure->nextNode(c); } }; struct AhoCorasick{ ACNode *node; AhoCorasick(){node = new ACNode;} void insert(char *s) { node->insert(s); } void build() { queue que; que.push(node); node->failure = node; while(que.size()){ ACNode *p = que.front(); que.pop(); for(int i=0;i<26;i++){ if(p->next[i]){ ACNode *failure = p->failure; while(!failure->next[i] && failure != node){ failure = failure->failure; } if (failure->next[i] && failure != p){ p->next[i]->failure = failure->next[i]; p->next[i]->val += failure->next[i]->val; }else{ p->next[i]->failure = node; } que.push(p->next[i]); } } } } }; int main(){ char s[SIZE], p[SIZE]; int m; AhoCorasick ac; scanf("%s%d", s, &m); for(int i=0;inextNode(s[i]); ans += now->val; } cout << ans << endl; return 0; }