#include #include #include #include //#include #include #include #include #include #include //#include #include #include #include //#include #include //#include #include #include #include #include #include const int dx[] = {1, 0, -1, 0}; const int dy[] = {0, -1, 0, 1}; using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector vi; typedef vector vll; typedef pair pii; string C[5050]; class Node { public: int value; Node* next[26]; Node() : value(0) { for (int i = 0; i < 26; i++) next[i] = NULL; } }; int main() { cin.tie(0); ios::sync_with_stdio(false); string S; cin >> S; int M; cin >> M; for (int i = 0; i < M; i++) { cin >> C[i]; } Node* root = new Node(); for (int i = 0; i < M; i++) { Node* now = root; for (char c : C[i]) { int num = c-'A'; if (now->next[num] == NULL) { now->next[num] = new Node(); } now = now->next[num]; } now->value += 1; } int n = S.size(); ll ans = 0; for (int i = 0; i < n; i++) { Node* now = root; for (int j = 0; j+i < n && now != NULL; j++) { now = now->next[S[i+j]-'A']; if (now != NULL) ans += now->value; } } cout << ans << endl; return 0; }