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 bool debug = 0;
const int chsize = 26;
const int chadd = 'a';
struct vex {
  vex* next[chsize];
  vex* go[chsize];
  vex* p;
  vex* link;
  int leaf;
  long long k;
  char pch;
  vex() {
    for (int i = 0; i < chsize; i++) {
      next[i] = nullptr;
      go[i] = nullptr;
    }
    p = nullptr;
    link = nullptr;
    leaf = 0;
    k = -1;
  }
};
void add_string(const string& s, vex* root) {
  vex* v = root;
  for (int i = 0; i < s.size(); i++) {
    if (v->next[s[i] - chadd] == nullptr) {
      vex* n = new vex();
      n->p = v;
      v->next[s[i] - chadd] = n;
      n->pch = s[i];
    }
    v = v->next[s[i] - chadd];
  }
  v->leaf += 1;
}
vex* go(vex* v, char c);
vex* get_link(vex* v) {
  if (v->link == nullptr) {
    if (v->p == nullptr)
      v->link = v;
    else if (v->p->p == nullptr)
      v->link = v->p;
    else
      v->link = go(get_link(v->p), v->pch);
  }
  return v->link;
}
vex* go(vex* v, char c) {
  c -= chadd;
  if (v->go[c] == nullptr) {
    if (v->next[c] != nullptr)
      v->go[c] = v->next[c];
    else if (v->p == nullptr)
      v->go[c] = v;
    else
      v->go[c] = go(get_link(v), c + chadd);
  }
  return v->go[c];
}
long long get_k(vex* v) {
  if (v->k == -1)
    if (v->p == nullptr)
      v->k = 0;
    else
      v->k = get_k(get_link(v)) + v->leaf;
  return v->k;
}
int main() {
  if (!debug) {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);
  }
  string t;
  cin >> t;
  int n = t.size();
  int q;
  cin >> q;
  vex* root1 = new vex();
  vex* root2 = new vex();
  while (q--) {
    string s;
    cin >> s;
    add_string(s, root1);
    reverse(s.begin(), s.end());
    add_string(s, root2);
  }
  vector<long long> a(n), b(n);
  vex* v = root1;
  for (int i = 0; i < n; i++) {
    v = go(v, t[i]);
    a[i] = get_k(v);
  }
  v = root2;
  for (int i = n - 1; i >= 0; i--) {
    v = go(v, t[i]);
    b[i] = get_k(v);
  }
  long long out = 0;
  for (int i = 0; i < n - 1; i++) {
    out += a[i] * b[i + 1];
  }
  cout << out;
  if (debug) cin >> n;
  return 0;
}