#include using namespace std; using ll = long long; using ul = unsigned long; using ull = unsigned long long; class Trie { public: int value; array next; Trie() : value(0) { next.fill(nullptr); } void insert(const string s) { if (s[0] == '\0') { ++this->value; return; } if (this->next[s[0] - BASE] == nullptr) this->next[s[0] - BASE] = new Trie(); this->next[s[0] - BASE]->insert(s.substr(1)); } bool find(const string s, int& count) { int countw{ count }; for (auto it = s.begin(); it != s.end(); ++it) { Trie* cur = this; auto its = it; while (its != s.end() && cur) { cur = cur->next[*its - BASE]; if (cur) count += cur->value; ++its; } } return countw > count; } private: const char BASE{ 'A' }; }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); string S; cin >> S; int M; cin >> M; vector C(M); for (auto&& it : C) cin >> it; Trie* root = new Trie(); for (const auto& it : C) root->insert(it); int cnt{ 0 }; root->find(S, cnt); cout << cnt << "\n"; return 0; }