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;
const int N = 2e5 + 10, inf = 0x3f3f3f3f;
char s[N], buf[N];
int n, m, C1[N], C2[N];
struct AC {
  static const int M = 26;
  int go[N][M], val[N], fa[N], tot, n;
  int newnode() {
    int u = ++tot;
    memset(go[u], 0, sizeof go[u]);
    val[u] = 0;
    return u;
  }
  void init() { tot = 0, newnode(); }
  void ins(char* s, int n) {
    int u = 1;
    for (int i = 0; i < n; u = go[u][s[i] - 'a'], ++i)
      if (!go[u][s[i] - 'a']) go[u][s[i] - 'a'] = newnode();
    val[u]++;
  }
  void dfs(int u, string s) {
    if (!u) return;
    cout << s << endl;
    printf("(%d %d)\n", u, val[u]);
    for (int i = 0; i < M; ++i) dfs(go[u][i], s + char(i + 'a'));
  }
  void build() {
    queue<int> q;
    for (int i = 0; i < M; ++i) {
      if (go[1][i])
        fa[go[1][i]] = 1, q.push(go[1][i]);
      else
        go[1][i] = 1;
    }
    while (q.size()) {
      int u = q.front();
      q.pop();
      val[u] += val[fa[u]];
      for (int i = 0; i < M; ++i) {
        if (go[u][i])
          fa[go[u][i]] = go[fa[u]][i], q.push(go[u][i]);
        else
          go[u][i] = go[fa[u]][i];
      }
    }
  }
} ac1, ac2;
int main() {
  ac1.init(), ac2.init();
  scanf("%s%d", s, &m), n = strlen(s);
  while (m--) {
    scanf("%s", buf);
    int l = strlen(buf);
    ac1.ins(buf, l);
    reverse(buf, buf + l);
    ac2.ins(buf, l);
  }
  ac1.build();
  ac2.build();
  for (int i = 0, u = 1; i < n; u = ac1.go[u][s[i] - 'a'], ++i)
    C1[i] = ac1.val[ac1.go[u][s[i] - 'a']];
  for (int i = n - 1, u = 1; i >= 0; u = ac2.go[u][s[i] - 'a'], --i)
    C2[i] = ac2.val[ac2.go[u][s[i] - 'a']];
  long long ans = 0;
  for (int i = 0; i < n - 1; ++i) ans += (long long)C1[i] * C2[i + 1];
  printf("%lld\n", ans);
  return 0;
}