#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define sz size() #define pb push_back #define mp make_pair #define fi first #define se second #define all(c) (c).begin(), (c).end() #define rep(i,a,b) for(int i=(a);i<(b);++i) #define clr(a, b) memset((a), (b) ,sizeof(a)) #define MOD 1000000007 string s; int f(int n, vector v){ int ret = 0; map ma; rep(i,0,v.sz){ long long key = 0; string s1 = v[i]; rep(j,0,s1.sz){ key += (s1[j]-'A')*pow(26,j); } ma[key]++; } long long key = 0; rep(i,0,n){ key += (s[i]-'A')*pow(26,i); } rep(i,n,s.sz){ ret += ma[key]; key /= 26; key += (s[i]-'A')*pow(26,n-1); } ret += ma[key]; return ret; } int main(){ cin>>s; int m; cin>>m; vector > v(11,vector()); rep(i,0,m){ string s1; cin>>s1; v[s1.sz].pb(s1); } int ans = 0; rep(i,1,11){ if(i<=s.sz){ ans += f(i,v[i]); } } cout << ans << endl; return 0; }