#include using namespace std; #define FOR(i,l,r) for(int i = (l);i < (r);i++) #define ALL(x) (x).begin(),(x).end() template void chmax(T& a,const T& b){if(a < b) a = b;} template void chmin(T& a,const T& b){if(b < a) a = b;} typedef long long ll; int N,M; string S; struct node{ bool ex; node *next [26]; }; node root{}; void add(string t) { node *p = &root; FOR(i,0,t.size()){ int key = t [i] - 'A'; if(p->next [key] == nullptr){ p->next [key] = new node(); } p = p->next [key]; } p->ex = true; } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> S >> M; N = S.size(); vector C(M); FOR(i,0,M){ cin >> C [i]; add(C [i]); } int ans = 0; FOR(i,0,N){ node *p = &root; for(int j = 0;j < 10 && i + j < N;j++){ int key = S [i + j] - 'A'; p = p->next [key]; if(p == nullptr) break; ans += p->ex; } } cout << ans << endl; return 0; }