#include using namespace std; using pii = pair; using ll = long long; #define rep(i, j) for(int i=0; i < (int)(j); i++) #define repeat(i, j, k) for(int i = (j); i < (int)(k); i++) #define all(v) v.begin(),v.end() #define debug(x) cerr << #x << " : " << x << endl template bool set_min(T &a, const T &b) { return a > b ? a = b, true : false; } template bool set_max(T &a, const T &b) { return a < b ? a = b, true : false; } // vector template istream& operator >> (istream &is , vector &v) { for(T &a : v) is >> a; return is; } template ostream& operator << (ostream &os , const vector &v) { for(const T &t : v) os << "\t" << t; return os << endl; } // pair template ostream& operator << (ostream &os , const pair &v) { return os << "<" << v.first << ", " << v.second << ">"; } const int INF = 1 << 30; const ll INFL = 1LL << 60; typedef unsigned long long ull; const ull HashBase = 100000007; vector pow_base; vector build_rolling_hash(const string &s){ int n = s.size(); vector hash(n+1); pow_base.resize(n+1); hash[0] = 0; pow_base[0] = 1; rep(i, n){ hash[i+1] = hash[i] * HashBase + s[i]; pow_base[i+1] = pow_base[i] * HashBase; } return hash; } ull build_hash(const string &s) { ull base = 1; ull ret = 0; for(int i = s.size() - 1; i >= 0; i--) { ret += s[i] * base; base *= HashBase; } return ret; } // hash of (l,r] ( 1-based index) ull get_rolling_hash(const vector &hash,int l,int r){ return hash[r] - hash[l] * pow_base[r-l]; } class Solver { public: bool solve() { string s; cin >> s; int m; cin >> m; set hash; rep(i, m) { string c; cin >> c; hash.insert(build_hash(c)); } vector rh = build_rolling_hash(s); ll ans = 0; repeat(i, 1, s.size() + 1) { repeat(j, 1, i + 1) { ans += hash.count(get_rolling_hash(rh, j - 1, i)); } } cout << ans << endl; return 0; } }; int main() { cin.tie(0); ios::sync_with_stdio(false); Solver s; s.solve(); return 0; }