#include #define rep(i,n) for(int i=0;i<(int)(n);i++) using namespace std; using ll = long long ; using P = pair ; using pll = pair; constexpr int INF = 1e9; constexpr long long LINF = 1e17; constexpr int MOD = 1000000007; constexpr double PI = 3.14159265358979323846; struct Rollinghash{ string S; int n; vector powb; vector H; unsigned long long int B = 1000007; unsigned long long int M = 1000000007; Rollinghash(string S):S(S){ n=(int)(S.size()); H.resize(n+1); powb.resize(n+1); init(); } void init(){ unsigned long long int p = 1; powb[0] = p; H[0] = 0; for(int i=1;i<=n;i++) powb[i] = (powb[i-1]*B)%M; for(int i=1;i<=n;i++) H[i] = (H[i-1]*B + S[i-1])%M; } //[l,r) unsigned long long int hash(int l,int r){ return (H[r] - (H[l] * powb[r-l])%M + M)%M; } }; int main(){ string S; cin >> S; Rollinghash Rs(S); map mp; for(int i=1;i<=min(10,(int)(S.size()));i++){ for(int j=0;j+i<=S.size();j++){ mp[Rs.hash(j,j+i)] ++; } } ll ans = 0; int m; cin >> m; rep(i,m){ string C; cin >> C; Rollinghash Rc(C); ans += mp[Rc.hash(0,C.size())]; } cout << ans << endl; return 0; }