#include #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--) #define all(x) (x).begin(), (x).end() #define sz(x) int(x.size()) #define yn(joken) cout<<((joken) ? "Yes" : "No")<; using vl = vector; using vs = vector; using vc = vector; using vd = vector; using vvi = vector>; using vvl = vector>; const int INF = 1e9; const ll LINF = 1e18; template bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } template vector make_vec(size_t a) { return vector(a); } template auto make_vec(size_t a, Ts... ts) { return vector(ts...))>(a, make_vec(ts...)); } template istream& operator>>(istream& is, vector& v) { for (int i = 0; i < int(v.size()); i++) { is >> v[i]; } return is; } template ostream& operator<<(ostream& os, const vector& v) { for (int i = 0; i < int(v.size()); i++) { os << v[i]; if (i < int(v.size()) - 1) os << ' '; } return os; } template struct KnuthMorrisPrattAlgorithm{ string pattern; int len; vector kmpNext; KnuthMorrisPrattAlgorithm(T P): pattern(P+'$'), len(int(P.size())+1), kmpNext(int(P.size())+2){} void build(){ kmpNext[0]=-1; int j=-1; for(int i=0;i=0 && pattern[i]!=pattern[j]) j=kmpNext[j]; j++; if(pattern[i+1]==pattern[j]) kmpNext[i+1]=kmpNext[j]; else kmpNext[i+1]=j; } } vector kmpSearch(T TEXT) { string text=TEXT+'%'; int text_pos=0; // テキストの比較位置 int pattern_pos=0; // パターンの比較位置 vector ret; // 見つかったパターンの先頭の位置を全て返す(0-indexed) build(); while (text_pos < int(text.size())) { if (text[text_pos] == pattern[pattern_pos]) { text_pos++; pattern_pos++; } else { if(pattern_pos==len-1) ret.push_back(text_pos-pattern_pos); if (kmpNext[pattern_pos] == kmpNext[0]) { text_pos++; pattern_pos = 0; } else pattern_pos = kmpNext[pattern_pos]; } } return ret; } }; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); string S; cin>>S; int M; cin>>M; ll ans=0; rep(_,M){ string C; cin>>C; KnuthMorrisPrattAlgorithm KMP(C); ans+=sz(KMP.kmpSearch(S)); } cout<