#include #include #include using namespace std; // subの先頭の文字と一致するstrのインデックスのリストを返却する vector findIndex(const string &str, const string &sub) { vector ret; int ub = str.size() - sub.size() + 1; for (int idx = 0; idx < ub; ++idx) { if (str[idx] == sub[0]) { ret.push_back(idx); } } return ret; } // strに含まれるsubの数を返却する int nSubstr(const string &str, const string &sub) { int n = 0; vector idxs = findIndex(str, sub); for (int idx : idxs) { if (sub.size() == 1) { ++n; continue; } bool found = true; for (int i = 1; i < sub.size(); ++i) { if (str[idx + i] != sub[i]) { found = false; break; } } if (found) ++n; } return n; } int main () { int count = 0; string str; vector subs; int n; cin >> str; cin >> n; for (int i = 0; i < n; ++i) { string tmp; cin >> tmp; subs.push_back(tmp); } for (string sub : subs) { count += nSubstr(str, sub); } cout << count << endl; }