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 T, n;
char Ls[400000 + 5], ps[400000 + 5];
long long ans;
long long read() {
  long long x = 0, F = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') F = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * F;
}
struct AC_automaton {
  int tr[400000 + 5][26], cnt;
  int C_end[400000 + 5], fail[400000 + 5], Ans[400000 + 5], lst[400000 + 5];
  void Clear() {
    cnt = 0;
    fail[0] = 0;
    memset(tr[0], 0, sizeof(tr[0]));
    memset(Ans, 0, sizeof(Ans));
  }
  void Insert(char *s, int id) {
    int p = 0, len = strlen(s);
    for (int i = 0; i < len; i++) {
      int num = s[i] - 'a';
      if (!tr[p][num]) {
        tr[p][num] = ++cnt;
        C_end[cnt] = 0;
        memset(tr[cnt], 0, sizeof(tr[cnt]));
        fail[cnt] = 0;
      }
      p = tr[p][num];
    }
    C_end[p]++;
  }
  void Build() {
    queue<int> Q;
    for (int i = 0; i < 26; i++)
      if (tr[0][i]) Q.push(tr[0][i]);
    while (!Q.empty()) {
      int k = Q.front();
      Q.pop();
      for (int i = 0; i < 26; i++)
        if (tr[k][i]) {
          int nxt = tr[k][i];
          fail[nxt] = tr[fail[k]][i];
          Q.push(nxt);
          lst[nxt] = C_end[fail[nxt]] ? fail[nxt] : lst[fail[nxt]];
        } else
          tr[k][i] = tr[fail[k]][i];
    }
  }
  void Query(char *s) {
    int p = 0;
    int len = strlen(s);
    for (int i = 0; i < len; i++) {
      if (s[i] < 'a' || s[i] > 'z') {
        p = 0;
        continue;
      }
      p = tr[p][s[i] - 'a'];
      for (int j = p; j; j = lst[j]) Ans[i] += C_end[j];
    }
  }
} ac, ac2;
int main() {
  ac.Clear();
  ac2.Clear();
  scanf("%s", Ls);
  n = read();
  int L;
  for (int i = 1; i <= n; i++) {
    scanf("%s", ps);
    ac.Insert(ps, i);
    L = strlen(ps);
    reverse(ps, ps + L);
    ac2.Insert(ps, i);
  }
  int len = strlen(Ls);
  ac.Build(), ac2.Build();
  ac.Query(Ls);
  reverse(Ls, Ls + len);
  ac2.Query(Ls);
  for (int i = 0; i < len - 1; i++)
    ans += 1LL * ac.Ans[i] * ac2.Ans[len - i - 2];
  printf("%lld", ans);
}