#include #include #include #include #include typedef int32_t i32; #define ALLOC(size,type) ((type*)calloc((size),sizeof(type))) typedef struct node { i32 cnt; struct node *next[26]; } node; node *NODE_ARRAY = NULL; node* add(node *t, char *s) { if (t == NULL) { t = NODE_ARRAY++; } if (*s == '\0') { t->cnt++; } else { i32 k = *s - 'A'; t->next[k] = add (t->next[k], s + 1); } return t; } void run (void) { char *s = ALLOC (50000 + 1, char); scanf ("%s", s); i32 m; scanf ("%" SCNi32, &m); NODE_ARRAY = ALLOC(m * 10 + 1, node); node *r = NULL; while (m--) { char c[11]; scanf ("%s", c); r = add (r, c); } i32 n = strlen (s); i32 ans = 0; for (i32 i = 0; i < n; ++i) { node *p = r; for (i32 j = 0; j < 10 && j < n - i; ++j) { p = p->next[s[i + j] - 'A']; if (p == NULL) break; ans += p->cnt; } } printf ("%" PRIi32 "\n", ans); } int main (void) { run(); return 0; }