#include using ll = long long; #define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i) #define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i) #define rreps(i, n) for (int i = ((int)(n)); i > 0; --i) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) #define repc2(i, s, n) for (int i = (s); i <= (int)(n); i++) #define bitrep(i, n) for (int i = 0, i##_len = (1 << (int)(n)); i < i##_len; i++) #define bitrrep(i, n) for (int i = (1 << (int)(n)) - 1ll; i >= 0; i--) constexpr int inf = 2000'000'000; constexpr ll linf = 4000000000000000000ll; constexpr ll M7 = 1000000007ll; constexpr ll M09 = 1000000009ll; constexpr ll M9 = 998244353ll; #define all(v) begin(v), end(v) #define rall(v) rbegin(v), rend(v) using namespace std; template inline ostream &operator<<(ostream &os, vector &v) { for (auto &e : v) os << e << " "; return os; } template std::ostream &operator<<(std::ostream &os, const std::pair &p) noexcept { return os << "(" << p.first << ", " << p.second << ")"; } template class Trie { private: struct Node { int next[char_size]; vector accept; // 末端がこの頂点になる単語のword_idx int c; // str[i] - base int common; // 頂点を共有する単語数 Node(int c) : c(c), common(0) { rep(i, char_size) next[i] = -1; } }; vector nodes; public: Trie() { nodes.push_back(Node(0)); } void insert(const string &word, int word_idx) { int node_id = 0; for (char c_ : word) { int c = c_ - base; if (nodes[node_id].next[c] == -1) { nodes[node_id].next[c] = int(nodes.size()); nodes.push_back(Node(c)); } ++nodes[node_id].common; node_id = nodes[node_id].next[c]; } ++nodes[node_id].common; nodes[node_id].accept.push_back(word_idx); } void insert(const string &word) { insert(word, nodes[0].common); } bool search(const string &word, bool prefix = false) { int node_id = 0; for (char c_ : word) { int c = c_ - base; if (nodes[node_id].next[c] == -1) return false; node_id = nodes[node_id].next[c]; } return prefix || (nodes[node_id].accept.size() > 0); } bool start_with(const string &prefix) { return search(prefix, true); } int word_count() const { return nodes[0].common; } int node_size() const { return nodes.size(); } }; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string s; int m; cin >> s >> m; vector v(m); rep(i, m) cin >> v.at(i); Trie<56, 'A'> trie; rep(i, m) trie.insert(v.at(i)); int ans = 0; reps(len, 10) { rep(i, s.size() - len + 1) { string t = s.substr(i, len); if (trie.search(t)) ans++; } } cout << ans << "\n"; return 0; }