#include #include #include #include #include #include #include using namespace std; using ll = long long; #define rep(i, j, n) for (ll i = j; i < (n); ++i) #define rrep(i, j, n) for (ll i = (n) - 1; j <= i; --i) #define all(a) a.begin(), a.end() template std::ostream &operator<<(std::ostream &os, std::vector &a) { for (size_t i = 0; i < a.size(); ++i) os << (i > 0 ? " " : "") << a[i]; return os << '\n'; } template std::istream &operator>>(std::istream &is, std::vector &a) { for (T &x : a) { is >> x; } return is; } template class trie { struct Node { Node *next[set_size] = {nullptr}; bool isleaf = false; }; public: trie() : nodes(1, new Node) {} // add the root node int ans = 0; bool search(const std::string &s) { Node *now = nodes[0]; for (const char &c : s) { int i = c - base_char; ans += now->isleaf; if (!now->next[i]) { return false; } now = now->next[i]; } ans += now->isleaf; return now->isleaf; } void insert(const std::string &s) { Node *now = nodes[0]; for (const char &c : s) { int i = c - base_char; if (!now->next[i]) { nodes.push_back(new Node); now->next[i] = nodes.back(); } // now->next[c]->count++; now = now->next[i]; } now->isleaf = true; } private: std::vector nodes; }; int main() { cin.tie(0)->sync_with_stdio(0); string s, t; int n; cin >> s >> n; trie<26, 'A'> trie; for (int i = 0; i < n; ++i) { cin >> t; trie.insert(t); } for (int i = 0; i < (int)s.size(); ++i) trie.search(s.substr(i, (int)s.size() - i)); cout << trie.ans << endl; }