#include <bits/stdc++.h>
using namespace std;
ostream &operator<<(ostream &out, string str) {
  for (char c : str) out << c;
  return out;
}
template <class L, class R>
ostream &operator<<(ostream &out, pair<L, R> p) {
  return out << "(" << p.first << ", " << p.second << ")";
}
template <class T>
auto operator<<(ostream &out, T a) -> decltype(a.begin(), out) {
  out << "{";
  for (auto it = a.begin(); it != a.end(); it = next(it))
    out << (it != a.begin() ? ", " : "") << *it;
  return out << "}";
}
void dump() { cerr << "\n"; }
template <class T, class... Ts>
void dump(T a, Ts... x) {
  cerr << a << ", ";
  dump(x...);
}
template <class T>
int size(T &&a) {
  return a.size();
}
using LL = long long;
using PII = pair<int, int>;
vector<int> sort_shifts(string &str) {
  int n = size(str), alf = 256;
  vector<int> p(n), c(n), cnt(max(alf, n));
  for (int i = 0; i < n; i++) cnt[str[i]]++;
  for (int i = 1; i <= alf - 1; i++) cnt[i] += cnt[i - 1];
  for (int i = 0; i < n; i++) p[--cnt[str[i]]] = i;
  for (int i = 1; i <= n - 1; i++) {
    c[p[i]] = c[p[i - 1]];
    if (str[p[i - 1]] != str[p[i]]) c[p[i]]++;
  }
  vector<int> pn(n), cn(n);
  for (int k = 0; (1 << k) < n; ++k) {
    auto mod = [&](int a, int b) { return (a + b + n) % n; };
    for (int i = 0; i < n; i++) pn[i] = mod(p[i], -(1 << k));
    fill(cnt.begin(), cnt.end(), 0);
    for (int i = 0; i < n; i++) cnt[c[pn[i]]]++;
    for (int i = 1; i <= size(cnt) - 1; i++) cnt[i] += cnt[i - 1];
    for (int i = n - 1; i >= 0; i--) p[--cnt[c[pn[i]]]] = pn[i];
    for (int i = 1; i <= n - 1; i++) {
      cn[p[i]] = cn[p[i - 1]];
      PII prev = {c[p[i - 1]], c[mod(p[i - 1], 1 << k)]};
      PII curr = {c[p[i]], c[mod(p[i], 1 << k)]};
      if (prev != curr) cn[p[i]]++;
    }
    swap(cn, c);
  }
  return p;
}
vector<int> suffix_array(string str) {
  str += "$";
  auto ret = sort_shifts(str);
  ret.erase(ret.begin());
  return ret;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string str;
  cin >> str;
  int n = size(str), q;
  cin >> q;
  vector<string> t(q);
  for (int i = 0; i < q; i++) cin >> t[i];
  auto get_beg = [&]() {
    auto sa = suffix_array(str);
    auto compare = [&](int i, int j, bool ret_equal) {
      for (int len = 0; len < size(t[j]); len++) {
        if (i + len == n) return false;
        if (str[i + len] > t[j][len]) return true;
        if (str[i + len] < t[j][len]) return false;
      }
      return ret_equal;
    };
    auto binsearch = [&](int i, bool ret_equal) {
      int l = 0, r = n;
      while (l < r) {
        int m = (l + r) / 2;
        if (compare(sa[m], i, ret_equal))
          r = m;
        else
          l = m + 1;
      }
      return l;
    };
    vector<int> pref(n + 1);
    for (int i = 0; i < q; i++) {
      pref[binsearch(i, true)]++;
      pref[binsearch(i, false)]--;
    }
    for (int i = 1; i <= n; i++) pref[i] += pref[i - 1];
    vector<int> ret(n);
    for (int i = 0; i < n; i++) ret[sa[i]] = pref[i];
    return ret;
  };
  auto beg1 = get_beg();
  reverse(str.begin(), str.end());
  for (int i = 0; i < q; i++) reverse(t[i].begin(), t[i].end());
  auto beg2 = get_beg();
  LL ans = 0;
  for (int i = 1; i <= n - 1; i++) ans += (LL)beg1[i] * beg2[n - i];
  cout << ans << "\n";
}

### Prompt

Please create a solution in Cpp to the following problem:

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>
using namespace std;
ostream &operator<<(ostream &out, string str) {
  for (char c : str) out << c;
  return out;
}
template <class L, class R>
ostream &operator<<(ostream &out, pair<L, R> p) {
  return out << "(" << p.first << ", " << p.second << ")";
}
template <class T>
auto operator<<(ostream &out, T a) -> decltype(a.begin(), out) {
  out << "{";
  for (auto it = a.begin(); it != a.end(); it = next(it))
    out << (it != a.begin() ? ", " : "") << *it;
  return out << "}";
}
void dump() { cerr << "\n"; }
template <class T, class... Ts>
void dump(T a, Ts... x) {
  cerr << a << ", ";
  dump(x...);
}
template <class T>
int size(T &&a) {
  return a.size();
}
using LL = long long;
using PII = pair<int, int>;
vector<int> sort_shifts(string &str) {
  int n = size(str), alf = 256;
  vector<int> p(n), c(n), cnt(max(alf, n));
  for (int i = 0; i < n; i++) cnt[str[i]]++;
  for (int i = 1; i <= alf - 1; i++) cnt[i] += cnt[i - 1];
  for (int i = 0; i < n; i++) p[--cnt[str[i]]] = i;
  for (int i = 1; i <= n - 1; i++) {
    c[p[i]] = c[p[i - 1]];
    if (str[p[i - 1]] != str[p[i]]) c[p[i]]++;
  }
  vector<int> pn(n), cn(n);
  for (int k = 0; (1 << k) < n; ++k) {
    auto mod = [&](int a, int b) { return (a + b + n) % n; };
    for (int i = 0; i < n; i++) pn[i] = mod(p[i], -(1 << k));
    fill(cnt.begin(), cnt.end(), 0);
    for (int i = 0; i < n; i++) cnt[c[pn[i]]]++;
    for (int i = 1; i <= size(cnt) - 1; i++) cnt[i] += cnt[i - 1];
    for (int i = n - 1; i >= 0; i--) p[--cnt[c[pn[i]]]] = pn[i];
    for (int i = 1; i <= n - 1; i++) {
      cn[p[i]] = cn[p[i - 1]];
      PII prev = {c[p[i - 1]], c[mod(p[i - 1], 1 << k)]};
      PII curr = {c[p[i]], c[mod(p[i], 1 << k)]};
      if (prev != curr) cn[p[i]]++;
    }
    swap(cn, c);
  }
  return p;
}
vector<int> suffix_array(string str) {
  str += "$";
  auto ret = sort_shifts(str);
  ret.erase(ret.begin());
  return ret;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string str;
  cin >> str;
  int n = size(str), q;
  cin >> q;
  vector<string> t(q);
  for (int i = 0; i < q; i++) cin >> t[i];
  auto get_beg = [&]() {
    auto sa = suffix_array(str);
    auto compare = [&](int i, int j, bool ret_equal) {
      for (int len = 0; len < size(t[j]); len++) {
        if (i + len == n) return false;
        if (str[i + len] > t[j][len]) return true;
        if (str[i + len] < t[j][len]) return false;
      }
      return ret_equal;
    };
    auto binsearch = [&](int i, bool ret_equal) {
      int l = 0, r = n;
      while (l < r) {
        int m = (l + r) / 2;
        if (compare(sa[m], i, ret_equal))
          r = m;
        else
          l = m + 1;
      }
      return l;
    };
    vector<int> pref(n + 1);
    for (int i = 0; i < q; i++) {
      pref[binsearch(i, true)]++;
      pref[binsearch(i, false)]--;
    }
    for (int i = 1; i <= n; i++) pref[i] += pref[i - 1];
    vector<int> ret(n);
    for (int i = 0; i < n; i++) ret[sa[i]] = pref[i];
    return ret;
  };
  auto beg1 = get_beg();
  reverse(str.begin(), str.end());
  for (int i = 0; i < q; i++) reverse(t[i].begin(), t[i].end());
  auto beg2 = get_beg();
  LL ans = 0;
  for (int i = 1; i <= n - 1; i++) ans += (LL)beg1[i] * beg2[n - i];
  cout << ans << "\n";
}

```