#include using namespace std; #define int long long #define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++) #define all(x) (x).begin(),(x).end() templatebool chmax(T &a,T b){if(abool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;} typedef pair pii; typedef vector vi; typedef vector vvi; const int inf = 1LL<<60; const int mod = 1e9 + 7; const double eps = 1e-9; /*{ }*/ class RollingHash{ public: const int K = 2; vector M, B; vector> hash, p; RollingHash(const string &s, vector b={107,311}) : M({1000000007, 1000000009}), B(b), hash(K), p(K){ int n = s.size(); for(int i = 0; i < K; i++){ hash[i].assign(n+1, 0); p[i].assign(n+1, 1); for(int j = 0; j < n; j++){ hash[i][j+1] = (hash[i][j]*B[i] + s[j])%M[i]; p[i][j+1] = p[i][j]*B[i]%M[i]; } } } vector find(int l, int r){ vector res(K); for(int i = 0; i < K; i++){ long long tmp = hash[i][r] + M[i] - hash[i][l]*p[i][r-l]%M[i]; res[i] = tmp >= M[i] ? tmp-M[i] : tmp; } return res; } }; signed main(){ srand((unsigned)time(NULL)); string s; cin >> s; long long B1 = rand()%10000+100000; long long B2 = rand()%10000+500000; RollingHash rh(s, {B1, B2}); map, int> cnt; rep(i, 0, s.size()) rep(j, 1, 11){ if(i+j <= s.size()){ cnt[rh.find(i, i+j)]++; } } int m; cin >> m; int ans = 0; rep(i, 0, m){ string c; cin >> c; RollingHash rh2(c, {B1, B2}); ans += cnt[rh2.find(0, c.size())]; } cout << ans << endl; return 0; }