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>
#pragma GCC target("pclmul")
using ul = std::uint32_t;
using ull = std::uint64_t;
using li = std::int32_t;
using ll = std::int64_t;
using uss = std::uint8_t;
const ul maxlen = 2e5;
class sam_t {
 public:
  ul las;
  class node {
   public:
    ul ch[26];
    ul len = 0;
    ul fa = 0;
    ul cnt = 0;
    node() { std::memset(ch, 0, sizeof(ch)); }
  };
  std::vector<node> st = std::vector<node>(maxlen + maxlen);
  void add(ul c) {
    ul p = las;
    ul np = las = st.size();
    st.push_back(node());
    st[np].len = st[p].len + 1;
    for (; p && !st[p].ch[c]; p = st[p].fa) {
      st[p].ch[c] = np;
    }
    if (!p) {
      st[np].fa = 1;
    } else {
      ul q = st[p].ch[c];
      if (st[q].len == st[p].len + 1) {
        st[np].fa = q;
      } else {
        ul nq = st.size();
        st.push_back(node());
        st[nq] = st[q];
        st[nq].len = st[p].len + 1;
        st[q].fa = st[np].fa = nq;
        for (; p && st[p].ch[c] == q; p = st[p].fa) {
          st[p].ch[c] = nq;
        }
      }
    }
  }
  void init() {
    las = 1;
    st.resize(0);
    st.resize(2);
  }
};
sam_t samt;
sam_t samr;
char str[maxlen + 2];
ul tlas[maxlen + 1];
ul rlas[maxlen + 2];
ul n;
ul ord[maxlen + maxlen];
int main() {
  std::scanf("%s", str + 1);
  ul len = std::strlen(str + 1);
  samt.init();
  samr.init();
  tlas[0] = 1;
  for (ul i = 1; i <= len; ++i) {
    samt.add(str[i] - 'a');
    tlas[i] = samt.las;
  }
  rlas[len + 1] = 1;
  for (ul i = len; i >= 1; --i) {
    samr.add(str[i] - 'a');
    rlas[i] = samr.las;
  }
  std::scanf("%u", &n);
  for (ul i = 1; i <= n; ++i) {
    std::scanf("%s", str + 1);
    ul len = std::strlen(str + 1);
    ul curr = 1;
    for (ul i = 1; i <= len; ++i) {
      curr = samt.st[curr].ch[str[i] - 'a'];
    }
    if (curr) {
      ++samt.st[curr].cnt;
    }
    curr = 1;
    for (ul i = len; i >= 1; --i) {
      curr = samr.st[curr].ch[str[i] - 'a'];
    }
    if (curr) {
      ++samr.st[curr].cnt;
    }
  }
  for (ul i = 1; i != samt.st.size(); ++i) {
    ord[i] = i;
  }
  std::sort(ord + 1, ord + samt.st.size(),
            [&](ul a, ul b) { return samt.st[a].len < samt.st[b].len; });
  for (ul it = 2; it != samt.st.size(); ++it) {
    ul i = ord[it];
    samt.st[i].cnt += samt.st[samt.st[i].fa].cnt;
  }
  for (ul i = 1; i != samr.st.size(); ++i) {
    ord[i] = i;
  }
  std::sort(ord + 1, ord + samr.st.size(),
            [&](ul a, ul b) { return samr.st[a].len < samr.st[b].len; });
  for (ul it = 2; it != samr.st.size(); ++it) {
    ul i = ord[it];
    samr.st[i].cnt += samr.st[samr.st[i].fa].cnt;
  }
  ull ans = 0;
  for (ul i = 0, j = 1; i <= len; ++i, ++j) {
    ans += ull(samt.st[tlas[i]].cnt) * ull(samr.st[rlas[j]].cnt);
  }
  std::printf("%llu\n", ans);
  return 0;
}