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

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
int n, l, i, k, p, u, h, j, b[1004], r[1004], number[200004], number2[200004];
long long sol;
string t, s[200004];
struct Trie {
  int nr;
  Trie *f[26], *pr;
  bool marked;
  int sumSuffixLinks;
  Trie() {
    nr = 0;
    pr = 0;
    marked = false;
    sumSuffixLinks = 0;
    for (h = 0; h <= 25; h++) f[h] = 0;
  }
} * node, *node2, *q[1000004];
Trie *T = new Trie;
Trie *T2 = new Trie;
void sumOf(Trie *node) {
  if (!node->marked) {
    node->sumSuffixLinks = node->nr;
    if (!(node->pr)->marked) sumOf(node->pr);
    node->sumSuffixLinks += (node->pr)->sumSuffixLinks;
    node->marked = true;
  }
  return;
}
void ins(Trie *node, int k, Trie *root) {
  if (k == s[i].size()) {
    node->nr++;
    return;
  }
  if (node->f[s[i][k] - 'a'] == 0) {
    node->f[s[i][k] - 'a'] = new Trie;
    (node->f[s[i][k] - 'a'])->pr = root;
  }
  ins(node->f[s[i][k] - 'a'], k + 1, root);
  return;
}
void g(Trie *root) {
  p = 1;
  u = 1;
  q[1] = root;
  while (p <= u) {
    node = q[p];
    for (i = 0; i <= 25; i++) {
      if (node->f[i] != 0) {
        node2 = node->pr;
        while ((node2 != root) && (node2->f[i] == 0)) node2 = node2->pr;
        if (((node2->f[i]) != 0) && (node2 != node))
          (node->f[i])->pr = node2->f[i];
        else
          (node->f[i])->pr = root;
        q[++u] = node->f[i];
      }
    }
    p++;
  }
  return;
}
int main() {
  cin >> t;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> s[i];
    ins(T, 0, T);
  }
  T->pr = T;
  T->marked = true;
  g(T);
  node = T;
  for (i = 0; i < t.size(); i++) {
    while ((node != T) && (node->f[t[i] - 'a'] == 0)) node = node->pr;
    if ((node->f[t[i] - 'a']) != 0) {
      node = node->f[t[i] - 'a'];
      if (!node->marked) sumOf(node);
      number[i] = node->sumSuffixLinks;
    } else
      number[i] = 0;
  }
  for (i = 1; i <= n; i++) {
    reverse(s[i].begin(), s[i].end());
    ins(T2, 0, T2);
  }
  T2->pr = T2;
  T2->marked = true;
  g(T2);
  node = T2;
  reverse(t.begin(), t.end());
  for (i = 0; i < (t.size() - 1); i++) {
    while ((node != T2) && (node->f[t[i] - 'a'] == 0)) node = node->pr;
    if ((node->f[t[i] - 'a']) != 0) {
      node = node->f[t[i] - 'a'];
      if (!node->marked) sumOf(node);
      number2[t.size() - i - 2] = node->sumSuffixLinks;
    } else
      number2[t.size() - i - 2] = 0;
  }
  sol = 0LL;
  for (i = 0; i < (t.size() - 1); i++)
    sol = (0LL) + sol + (1LL) * number[i] * number2[i];
  cout << sol << '\n';
  return 0;
}