#include #include #include #include #include #include #include #include #include #include using namespace std; using ll = int64_t; #define rep(i, j, n) for (int i = j; i < (int)n; ++i) #define rrep(i, j, n) for (int i = (int)n - 1; j <= i; --i) template std::ostream& operator<<(std::ostream& os, std::vector& a) { os << "{"; for (size_t i = 0; i < a.size(); ++i) os << (i > 0 ? "," : "") << a[i]; return os << "}"; } class trie { public: trie(size_t max_size) { size = 1; // only root next.assign(26, vector(max_size, -1)); end.assign(max_size, false); } int search(string s) { int now = 0; int res = 0; for (char c : s) { if (next[c - 'A'][now] == -1) return res + end[now]; res += end[now]; now = next[c - 'A'][now]; } return end[now] + res; } void insert(string s) { int now = 0; for (char c : s) { if (next[c - 'A'][now] == -1) next[c - 'A'][now] = size++; now = next[c - 'A'][now]; } end[now] = true; } private: vector> next; vector end; int size; }; int main() { string s, t; int n; cin >> s >> n; trie tr(50005); rep(i, 0, n) { cin >> t; tr.insert(t); } int ans = 0; rep(i, 0, s.size()) { ans += tr.search(s.substr(i, s.size() - i)); } cout << ans << '\n'; return 0; }