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 = 200010;
int n, m, A[N], B[N], len[N], sum[N];
char s[N], ss[N];
vector<int> G[N];
int tot, son[N][26], id[N], fail[N], q[N], am[N];
void init() {
  memset(son, 0, sizeof(son));
  for (int i = (0); i <= (tot); ++i) G[i].clear();
  memset(id, 0, sizeof(id));
  memset(q, 0, sizeof(q));
  memset(am, 0, sizeof(am));
  memset(sum, 0, sizeof(sum));
  memset(fail, 0, sizeof(fail));
  tot = 0;
}
void ins(int p) {
  for (int l = strlen(s), first = 0, i = 0, w; i < l; ++i) {
    if (!son[first][w = s[i] - 'a']) son[first][w] = ++tot;
    first = son[first][w];
    if (i == l - 1) id[first] = p, ++am[first];
  }
}
void make() {
  int h = 1, t = 0, i, j, first;
  fail[0] = -1;
  for (i = 0; i < 26; ++i)
    if (son[0][i]) q[++t] = son[0][i];
  while (h <= t)
    for (first = q[h++], i = 0; i < 26; ++i)
      if (son[first][i])
        fail[son[first][i]] = son[fail[first]][i], q[++t] = son[first][i];
      else
        son[first][i] = son[fail[first]][i];
}
void find(char* s, int A[]) {
  for (int l = strlen(s), first = 0, i = 0, w, j; i < l; ++i) {
    first = son[first][w = s[i] - 'a'];
    A[i] += sum[first];
  }
}
void dfs(int u, int fa) {
  if (~fa) sum[u] += sum[fa];
  for (int v : G[u]) dfs(v, u);
}
string str[N];
int main() {
  scanf(" %s", ss);
  int L = strlen(ss);
  init();
  scanf("%d", &m);
  for (int i = (1); i <= (m); ++i) {
    scanf(" %s", s), len[i] = strlen(s);
    str[i] = string(s);
    ins(i);
  }
  make();
  for (int i = (1); i <= (tot); ++i)
    if (id[i])
      sum[i] = am[i];
    else
      sum[i] = 0;
  for (int i = (1); i <= (tot); ++i)
    if (~fail[i]) G[fail[i]].push_back(i);
  dfs(0, -1);
  find(ss, B);
  init();
  reverse(ss, ss + L);
  for (int i = (1); i <= (m); ++i) {
    reverse(str[i].begin(), str[i].end());
    memcpy(s, str[i].c_str(), sizeof(char) * len[i]);
    s[str[i].size()] = '\0';
    ins(i);
  }
  make();
  for (int i = (0); i <= (tot); ++i)
    if (id[i])
      sum[i] = am[i];
    else
      sum[i] = 0;
  for (int i = (0); i <= (tot); ++i)
    if (~fail[i]) G[fail[i]].push_back(i);
  dfs(0, -1);
  find(ss, A);
  reverse(A, A + L);
  long long ans = 0;
  for (int i = (1); i <= (L - 1); ++i) ans += (long long)B[i - 1] * A[i];
  printf("%lld\n", ans);
  return 0;
}