#include <bits/stdc++.h>
using namespace std;
struct Aho {
  Aho *son[26];
  Aho *fail;
  int cntstr, faildp;
  Aho() {
    for (int i = 0; i < 26; ++i) son[i] = NULL;
    fail = NULL;
    cntstr = 0;
    faildp = -1;
  }
};
void insert(Aho *x, int i, const string &str) {
  if (i < str.size()) {
    if (x->son[str[i] - 'a'] == NULL) {
      x->son[str[i] - 'a'] = new Aho();
    }
    insert(x->son[str[i] - 'a'], i + 1, str);
  } else {
    x->cntstr++;
  }
}
void calcFailEdges(Aho *root) {
  deque<Aho *> q;
  root->fail = root;
  q.push_back(root);
  while (!q.empty()) {
    Aho *x = q.front();
    q.pop_front();
    for (int i = 0; i < 26; ++i) {
      if (x->son[i] != NULL) {
        q.push_back(x->son[i]);
        Aho *pnt = x->fail;
        if (x == root)
          x->son[i]->fail = root;
        else {
          while (pnt != root && pnt->son[i] == NULL) {
            pnt = pnt->fail;
          }
          if (pnt->son[i] != NULL)
            x->son[i]->fail = pnt->son[i];
          else
            x->son[i]->fail = root;
        }
      }
    }
  }
}
int getDp(Aho *t) {
  if (t->faildp == -1) {
    t->faildp = t->cntstr;
    t->faildp += getDp(t->fail);
  }
  return t->faildp;
}
const int MAX_N = 200000;
Aho *state[1 + MAX_N];
Aho *advance(Aho *t, char ch) {
  while (t->fail != t && t->son[ch - 'a'] == NULL) t = t->fail;
  if (t->son[ch - 'a'] == NULL) return t;
  return t->son[ch - 'a'];
}
Aho *state1[MAX_N], *state2[MAX_N];
void doStuff(int n, Aho **state, const string &str, const vector<string> &vec) {
  Aho *T = new Aho();
  for (int i = 0; i < n; ++i) insert(T, 0, vec[i]);
  T->faildp = T->cntstr;
  calcFailEdges(T);
  Aho *pnt = T;
  for (int i = 1; i <= str.size(); ++i) {
    pnt = advance(pnt, str[i - 1]);
    state[i] = pnt;
  }
}
int main() {
  int n;
  string str;
  cin >> str >> n;
  vector<string> vec;
  for (int i = 0; i < n; ++i) {
    string p;
    cin >> p;
    vec.push_back(p);
  }
  doStuff(n, state1, str, vec);
  for (int i = 0; i < n; ++i) reverse(vec[i].begin(), vec[i].end());
  reverse(str.begin(), str.end());
  doStuff(n, state2, str, vec);
  long long rez = 0LL;
  for (int i = 1; i < str.size(); ++i)
    rez = (long long)getDp(state1[i]) * getDp(state2[str.size() - i]) + rez;
  printf("%lld", rez);
  return 0;
}

### Prompt

Create a solution in cpp for the following 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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct Aho {
  Aho *son[26];
  Aho *fail;
  int cntstr, faildp;
  Aho() {
    for (int i = 0; i < 26; ++i) son[i] = NULL;
    fail = NULL;
    cntstr = 0;
    faildp = -1;
  }
};
void insert(Aho *x, int i, const string &str) {
  if (i < str.size()) {
    if (x->son[str[i] - 'a'] == NULL) {
      x->son[str[i] - 'a'] = new Aho();
    }
    insert(x->son[str[i] - 'a'], i + 1, str);
  } else {
    x->cntstr++;
  }
}
void calcFailEdges(Aho *root) {
  deque<Aho *> q;
  root->fail = root;
  q.push_back(root);
  while (!q.empty()) {
    Aho *x = q.front();
    q.pop_front();
    for (int i = 0; i < 26; ++i) {
      if (x->son[i] != NULL) {
        q.push_back(x->son[i]);
        Aho *pnt = x->fail;
        if (x == root)
          x->son[i]->fail = root;
        else {
          while (pnt != root && pnt->son[i] == NULL) {
            pnt = pnt->fail;
          }
          if (pnt->son[i] != NULL)
            x->son[i]->fail = pnt->son[i];
          else
            x->son[i]->fail = root;
        }
      }
    }
  }
}
int getDp(Aho *t) {
  if (t->faildp == -1) {
    t->faildp = t->cntstr;
    t->faildp += getDp(t->fail);
  }
  return t->faildp;
}
const int MAX_N = 200000;
Aho *state[1 + MAX_N];
Aho *advance(Aho *t, char ch) {
  while (t->fail != t && t->son[ch - 'a'] == NULL) t = t->fail;
  if (t->son[ch - 'a'] == NULL) return t;
  return t->son[ch - 'a'];
}
Aho *state1[MAX_N], *state2[MAX_N];
void doStuff(int n, Aho **state, const string &str, const vector<string> &vec) {
  Aho *T = new Aho();
  for (int i = 0; i < n; ++i) insert(T, 0, vec[i]);
  T->faildp = T->cntstr;
  calcFailEdges(T);
  Aho *pnt = T;
  for (int i = 1; i <= str.size(); ++i) {
    pnt = advance(pnt, str[i - 1]);
    state[i] = pnt;
  }
}
int main() {
  int n;
  string str;
  cin >> str >> n;
  vector<string> vec;
  for (int i = 0; i < n; ++i) {
    string p;
    cin >> p;
    vec.push_back(p);
  }
  doStuff(n, state1, str, vec);
  for (int i = 0; i < n; ++i) reverse(vec[i].begin(), vec[i].end());
  reverse(str.begin(), str.end());
  doStuff(n, state2, str, vec);
  long long rez = 0LL;
  for (int i = 1; i < str.size(); ++i)
    rez = (long long)getDp(state1[i]) * getDp(state2[str.size() - i]) + rez;
  printf("%lld", rez);
  return 0;
}

```