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 SIZE = 2e5 + 1, sqrtSIZE = sqrt(SIZE) + 1;
const int TAMA = 'z' - 'a' + 1;
struct Trie {
  struct node {
    int hij[TAMA], lon, ca;
    node(int _lon) {
      lon = _lon;
      ca = 0;
      for (int i = 0; i < TAMA; i++) hij[i] = -1;
    }
  };
  vector<node> trie;
  Trie() { trie.push_back(node(0)); }
  int ascii(char l) { return l - 'a'; }
  void insert_word(const string &s) {
    int nod = 0;
    for (int i = 0; i < s.size(); i++) {
      if (trie[nod].hij[ascii(s[i])] == -1) {
        trie[nod].hij[ascii(s[i])] = trie.size();
        trie.push_back(node(trie[nod].lon + 1));
      }
      nod = trie[nod].hij[ascii(s[i])];
    }
    trie[nod].ca++;
  }
  void search(string s, vector<int> &I, vector<int> &F, int ini) {
    int nod = 0;
    for (int i = 0; i < s.size(); i++) {
      if (ini + i >= I.size()) break;
      if (trie[nod].hij[ascii(s[i])] == -1) {
        break;
      }
      nod = trie[nod].hij[ascii(s[i])];
      I[ini] += trie[nod].ca;
      F[ini + i] += trie[nod].ca;
    }
  }
};
void KMP(string S, string P, vector<int> &I, vector<int> &F) {
  int TS = S.size(), TP = P.size();
  S = " " + S;
  P = " " + P;
  std::vector<int> TF(P.size() + 1);
  TF[1] = 0;
  for (int i = 2; i <= TP; i++) {
    int aux = TF[i - 1];
    while (aux > 0 && P[aux + 1] != P[i]) aux = TF[aux];
    if (P[aux + 1] == P[i]) aux++;
    TF[i] = aux;
  }
  int aux = 0;
  for (int i = 1; i <= TS; i++) {
    while (aux > 0 && P[aux + 1] != S[i]) aux = TF[aux];
    if (P[aux + 1] == S[i]) aux++;
    if (aux == TP) {
      F[i - 1]++;
      I[i - aux]++;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string S;
  cin >> S;
  int N;
  cin >> N;
  Trie t;
  std::vector<int> I(S.size()), F(S.size());
  for (int i = 1; i <= N; i++) {
    string p;
    cin >> p;
    if (p.size() < sqrtSIZE)
      t.insert_word(p);
    else
      KMP(S, p, I, F);
  }
  for (int i = 0; i < S.size(); i++)
    t.search(S.substr(i, min(sqrtSIZE - 1, (int)S.size() - i)), I, F, i);
  long long sol = 0;
  for (int i = 0; i < S.size() - 1; i++) sol += 1LL * F[i] * I[i + 1];
  cout << sol << '\n';
  return 0;
}