#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops", "no-stack-protector")
using namespace std;
template <class T>
struct rge {
  T b, e;
};
template <class T>
rge<T> range(T i, T j) {
  return rge<T>{i, j};
}
template <class T>
auto dud(T *x) -> decltype(cerr << *x, 0);
template <class T>
char dud(...);
struct debug {
  template <class T>
  debug &operator<<(const T &) {
    return *this;
  }
};
const int N = 2e5 + 5;
string second, t[N];
int beg[N], stop[N];
int n;
struct AhoCorasick {
  vector<map<char, int> > trie, fgo;
  vector<int> link, cnt;
  AhoCorasick() { newNode(); }
  int newNode() {
    trie.push_back({}), fgo.push_back({}), link.push_back(0), cnt.push_back(0);
    return int(trie.size()) - 1;
  }
  void insert(string &second, int u = 0) {
    for (char c : second) {
      if (!trie[u][c]) trie[u][c] = newNode();
      u = trie[u][c];
    }
    cnt[u]++;
  }
  int go(int u, char c) {
    while (u && !trie[u].count(c)) u = link[u];
    return trie[u][c];
  }
  void pushLinks() {
    queue<int> qu;
    qu.push(0);
    while (!qu.empty()) {
      int u = qu.front();
      qu.pop();
      for (auto &[c, v] : trie[u]) {
        if (v == 0) {
          v = trie[link[u]][c];
          continue;
        }
        link[v] = u ? go(link[u], c) : 0;
        cnt[v] += cnt[link[v]];
        qu.push(v);
      }
    }
  }
  void match(string &second, int u = 0) {
    for (auto i = (0) - ((0) > (int(second.size())));
         i != int(second.size()) - ((0) > (int(second.size())));
         i += 1 - 2 * ((0) > (int(second.size())))) {
      char c = second[i];
      u = go(u, c);
      stop[i] += cnt[u];
    }
  }
  void revMatch(string &second, int u = 0) {
    for (auto i = (int(second.size())) - ((int(second.size())) > (0));
         i != 0 - ((int(second.size())) > (0));
         i += 1 - 2 * ((int(second.size())) > (0))) {
      char c = second[i];
      u = go(u, c);
      beg[i] += cnt[u];
    }
  }
};
int main() {
  cin.tie(0)->sync_with_stdio(0), cout.tie(0);
  while (cin >> second) {
    cin >> n;
    AhoCorasick aho, revAho;
    for (auto i = (1) - ((1) > (n + 1)); i != n + 1 - ((1) > (n + 1));
         i += 1 - 2 * ((1) > (n + 1))) {
      cin >> t[i];
      aho.insert(t[i]);
    }
    for (auto i = (1) - ((1) > (n + 1)); i != n + 1 - ((1) > (n + 1));
         i += 1 - 2 * ((1) > (n + 1))) {
      reverse(begin(t[i]), end(t[i]));
      revAho.insert(t[i]);
    }
    aho.pushLinks(), revAho.pushLinks();
    for (auto i = (0) - ((0) > (int(second.size()) + 1));
         i != int(second.size()) + 1 - ((0) > (int(second.size()) + 1));
         i += 1 - 2 * ((0) > (int(second.size()) + 1)))
      beg[i] = stop[i] = 0;
    aho.match(second);
    revAho.revMatch(second);
    long long ans = 0;
    for (auto i = (1) - ((1) > (int(second.size())));
         i != int(second.size()) - ((1) > (int(second.size())));
         i += 1 - 2 * ((1) > (int(second.size())))) {
      int pref = stop[i - 1], suf = beg[i];
      ans += 1LL * pref * suf;
      debug() << " "
              << "i"
                 ": "
              << (i)
              << " "
                 " "
              << "pref"
                 ": "
              << (pref)
              << " "
                 " "
              << "suf"
                 ": "
              << (suf) << " ";
    }
    cout << ans << '\n';
    debug();
  }
  return 0;
}

### Prompt

Construct a Cpp code solution to the problem outlined:

You are given a string t and n strings s_1, s_2, ..., s_n. All strings consist of lowercase Latin letters.

Let f(t, s) be the number of occurences of string s in string t. For example, f('aaabacaa', 'aa') = 3, and f('ababa', 'aba') = 2.

Calculate the value of ∑_{i=1}^{n} ∑_{j=1}^{n} f(t, s_i + s_j), where s + t is the concatenation of strings s and t. Note that if there are two pairs i_1, j_1 and i_2, j_2 such that s_{i_1} + s_{j_1} = s_{i_2} + s_{j_2}, you should include both f(t, s_{i_1} + s_{j_1}) and f(t, s_{i_2} + s_{j_2}) in answer.

Input

The first line contains string t (1 ≤ |t| ≤ 2 ⋅ 10^5).

The second line contains integer n (1 ≤ n ≤ 2 ⋅ 10^5).

Each of next n lines contains string s_i (1 ≤ |s_i| ≤ 2 ⋅ 10^5).

It is guaranteed that ∑_{i=1}^{n} |s_i| ≤ 2 ⋅ 10^5. All strings consist of lowercase English letters.

Output

Print one integer — the value of ∑_{i=1}^{n} ∑_{j=1}^{n} f(t, s_i + s_j).

Examples

Input


aaabacaa
2
a
aa


Output


5


Input


aaabacaa
4
a
a
a
b


Output


33

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops", "no-stack-protector")
using namespace std;
template <class T>
struct rge {
  T b, e;
};
template <class T>
rge<T> range(T i, T j) {
  return rge<T>{i, j};
}
template <class T>
auto dud(T *x) -> decltype(cerr << *x, 0);
template <class T>
char dud(...);
struct debug {
  template <class T>
  debug &operator<<(const T &) {
    return *this;
  }
};
const int N = 2e5 + 5;
string second, t[N];
int beg[N], stop[N];
int n;
struct AhoCorasick {
  vector<map<char, int> > trie, fgo;
  vector<int> link, cnt;
  AhoCorasick() { newNode(); }
  int newNode() {
    trie.push_back({}), fgo.push_back({}), link.push_back(0), cnt.push_back(0);
    return int(trie.size()) - 1;
  }
  void insert(string &second, int u = 0) {
    for (char c : second) {
      if (!trie[u][c]) trie[u][c] = newNode();
      u = trie[u][c];
    }
    cnt[u]++;
  }
  int go(int u, char c) {
    while (u && !trie[u].count(c)) u = link[u];
    return trie[u][c];
  }
  void pushLinks() {
    queue<int> qu;
    qu.push(0);
    while (!qu.empty()) {
      int u = qu.front();
      qu.pop();
      for (auto &[c, v] : trie[u]) {
        if (v == 0) {
          v = trie[link[u]][c];
          continue;
        }
        link[v] = u ? go(link[u], c) : 0;
        cnt[v] += cnt[link[v]];
        qu.push(v);
      }
    }
  }
  void match(string &second, int u = 0) {
    for (auto i = (0) - ((0) > (int(second.size())));
         i != int(second.size()) - ((0) > (int(second.size())));
         i += 1 - 2 * ((0) > (int(second.size())))) {
      char c = second[i];
      u = go(u, c);
      stop[i] += cnt[u];
    }
  }
  void revMatch(string &second, int u = 0) {
    for (auto i = (int(second.size())) - ((int(second.size())) > (0));
         i != 0 - ((int(second.size())) > (0));
         i += 1 - 2 * ((int(second.size())) > (0))) {
      char c = second[i];
      u = go(u, c);
      beg[i] += cnt[u];
    }
  }
};
int main() {
  cin.tie(0)->sync_with_stdio(0), cout.tie(0);
  while (cin >> second) {
    cin >> n;
    AhoCorasick aho, revAho;
    for (auto i = (1) - ((1) > (n + 1)); i != n + 1 - ((1) > (n + 1));
         i += 1 - 2 * ((1) > (n + 1))) {
      cin >> t[i];
      aho.insert(t[i]);
    }
    for (auto i = (1) - ((1) > (n + 1)); i != n + 1 - ((1) > (n + 1));
         i += 1 - 2 * ((1) > (n + 1))) {
      reverse(begin(t[i]), end(t[i]));
      revAho.insert(t[i]);
    }
    aho.pushLinks(), revAho.pushLinks();
    for (auto i = (0) - ((0) > (int(second.size()) + 1));
         i != int(second.size()) + 1 - ((0) > (int(second.size()) + 1));
         i += 1 - 2 * ((0) > (int(second.size()) + 1)))
      beg[i] = stop[i] = 0;
    aho.match(second);
    revAho.revMatch(second);
    long long ans = 0;
    for (auto i = (1) - ((1) > (int(second.size())));
         i != int(second.size()) - ((1) > (int(second.size())));
         i += 1 - 2 * ((1) > (int(second.size())))) {
      int pref = stop[i - 1], suf = beg[i];
      ans += 1LL * pref * suf;
      debug() << " "
              << "i"
                 ": "
              << (i)
              << " "
                 " "
              << "pref"
                 ": "
              << (pref)
              << " "
                 " "
              << "suf"
                 ": "
              << (suf) << " ";
    }
    cout << ans << '\n';
    debug();
  }
  return 0;
}

```