#include #include #include using namespace std; int find_next_head(const std::string& str, const std::string& ptn, int begin) { for (uint i = begin; i < str.size(); ++i) { if (str[i] == ptn[0]) { return i; } } return -1; } std::pair find_next_substr(const std::string& str, const std::string& ptn, int begin) { int pos = find_next_head(str, ptn, begin); if (pos == -1 || str.size() < begin + ptn.size()) { return {false, -1}; } for (uint i = 0; i < ptn.size(); ++i) { if (str[pos + i] != ptn[i]) { return {false, pos + 1}; } } return {true, pos + 1}; } int count_substr(const std::string& str, const std::string& ptn) { int count = 0; std::pair m = find_next_substr(str, ptn, 0); bool found = m.first; int next_pos = m.second; if (found) { count++; } while (next_pos != -1) { m = find_next_substr(str, ptn, next_pos); found = m.first; next_pos = m.second; if (found) { count++; } } return found ? count + 1 : count; } int main() { string S, *C; int M; cin >> S >> M; C = new string[M]; for (int i = 0; i < M; ++i) { cin >> C[i]; } int sum = 0; for (int i = 0; i < M; ++i) { sum += count_substr(S, C[i]); } cout << sum << endl; }