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;
template <class T>
inline void read(T &x) {
  x = 0;
  char c = getchar();
  while (!isdigit(c)) c = getchar();
  while (isdigit(c)) x = x * 10 + (c & 15), c = getchar();
}
int n, m, tr1[200005][26], tot1, nxt1[200005], ed1[200005], tr2[200005][26],
    tot2, nxt2[200005], ed2[200005], f[200005], g[200005], q[200005], l = 1, r;
long long ans;
char s[200005], t[200005];
signed main() {
  scanf("%s", t + 1), m = strlen(t + 1), read(n);
  for (int i = 1, len, no = 0; i <= n; i++) {
    scanf("%s", s + 1), len = strlen(s + 1);
    for (int j = 1; j <= len; j++)
      no = (tr1[no][s[j] - 'a'] ? tr1[no][s[j] - 'a']
                                : tr1[no][s[j] - 'a'] = ++tot1);
    ++ed1[no], no = 0;
    for (int j = len; j >= 1; j--)
      no = (tr2[no][s[j] - 'a'] ? tr2[no][s[j] - 'a']
                                : tr2[no][s[j] - 'a'] = ++tot2);
    ++ed2[no], no = 0;
  }
  for (int i = 0; i < 26; i++)
    if (tr1[0][i]) q[++r] = tr1[0][i];
  while (l <= r) {
    int x = q[l++];
    for (int i = 0; i < 26; i++)
      if (tr1[x][i])
        q[++r] = tr1[x][i], nxt1[tr1[x][i]] = tr1[nxt1[x]][i];
      else
        tr1[x][i] = tr1[nxt1[x]][i];
    ed1[x] += ed1[nxt1[x]];
  }
  l = 1, r = 0;
  for (int i = 0; i < 26; i++)
    if (tr2[0][i]) q[++r] = tr2[0][i];
  while (l <= r) {
    int x = q[l++];
    for (int i = 0; i < 26; i++)
      if (tr2[x][i])
        q[++r] = tr2[x][i], nxt2[tr2[x][i]] = tr2[nxt2[x]][i];
      else
        tr2[x][i] = tr2[nxt2[x]][i];
    ed2[x] += ed2[nxt2[x]];
  }
  for (int i = 1, no = 0; i <= m; i++) no = tr1[no][t[i] - 'a'], f[i] = ed1[no];
  for (int i = m, no = 0; i >= 1; i--) no = tr2[no][t[i] - 'a'], g[i] = ed2[no];
  for (int i = 1; i < m; i++) ans += (long long)f[i] * g[i + 1];
  printf("%lld\n", ans);
  return 0;
}