#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream& operator<<(ostream& out, vector<T>& v) {
  out << "[";
  for (auto k : v) out << k << " ";
  out << "]"
      << "\n";
  return out;
}
struct vertex {
  map<char, int> next, go;
  int p, link, ini;
  bool visto = false;
  char pch;
  long long peso = 0;
  vertex(int p = -1, char pch = -1) : p(p), pch(pch), link(-1), peso(0) {}
};
vector<vertex> t;
void aho_init() {
  t.clear();
  t.push_back(vertex());
  t.push_back(vertex());
}
const int maxn = 3e5;
vector<pair<int, int> > pos;
void add_string(string s, int ini) {
  int v = ini;
  t[v].ini = ini;
  for (int i = 0; i < int(s.size()); i++) {
    char c = s[i];
    if (!t[v].next.count(c)) {
      t[v].next[c] = t.size();
      t.push_back(vertex(v, c));
    }
    v = t[v].next[c];
    t[v].ini = ini;
    pos.push_back({i, v});
  }
  t[v].peso++;
}
int go(int v, char c);
int get_link(int v) {
  if (t[v].link < 0)
    if (v < 2 || t[v].p < 2)
      t[v].link = t[v].ini;
    else
      t[v].link = go(get_link(t[v].p), t[v].pch);
  return t[v].link;
}
int go(int v, char c) {
  if (!t[v].go.count(c))
    if (t[v].next.count(c))
      t[v].go[c] = t[v].next[c];
    else
      t[v].go[c] = v < 2 ? v : go(get_link(v), c);
  return t[v].go[c];
}
long long der[maxn], rev[maxn];
int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);
  string st, s = "";
  cin >> st;
  int n, m = st.size();
  cin >> n;
  aho_init();
  for (int i = 0; i < int(n); i++) {
    cin >> s;
    add_string(s, 0);
    reverse(s.begin(), s.end());
    add_string(s, 1);
  }
  sort(pos.begin(), pos.end());
  for (auto p : pos) {
    int j = p.second;
    if (t[j].visto) continue;
    t[j].visto = true;
    int l = get_link(j);
    if (l >= 0) {
      t[j].peso += t[l].peso;
    }
  }
  int v = 0;
  for (int i = 0; i < int(m); i++) {
    v = go(v, st[i]);
    der[i] = t[v].peso;
  }
  v = 1;
  for (int i = int(m) - 1; i >= 0; i--) {
    v = go(v, st[i]);
    rev[i] = t[v].peso;
  }
  long long res = 0;
  for (int i = 0; i < int(m - 1); i++) res += der[i] * rev[i + 1];
  cout << res << "\n";
  return 0;
}

### Prompt

Your challenge is to write a Cpp solution to 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;
template <class T>
ostream& operator<<(ostream& out, vector<T>& v) {
  out << "[";
  for (auto k : v) out << k << " ";
  out << "]"
      << "\n";
  return out;
}
struct vertex {
  map<char, int> next, go;
  int p, link, ini;
  bool visto = false;
  char pch;
  long long peso = 0;
  vertex(int p = -1, char pch = -1) : p(p), pch(pch), link(-1), peso(0) {}
};
vector<vertex> t;
void aho_init() {
  t.clear();
  t.push_back(vertex());
  t.push_back(vertex());
}
const int maxn = 3e5;
vector<pair<int, int> > pos;
void add_string(string s, int ini) {
  int v = ini;
  t[v].ini = ini;
  for (int i = 0; i < int(s.size()); i++) {
    char c = s[i];
    if (!t[v].next.count(c)) {
      t[v].next[c] = t.size();
      t.push_back(vertex(v, c));
    }
    v = t[v].next[c];
    t[v].ini = ini;
    pos.push_back({i, v});
  }
  t[v].peso++;
}
int go(int v, char c);
int get_link(int v) {
  if (t[v].link < 0)
    if (v < 2 || t[v].p < 2)
      t[v].link = t[v].ini;
    else
      t[v].link = go(get_link(t[v].p), t[v].pch);
  return t[v].link;
}
int go(int v, char c) {
  if (!t[v].go.count(c))
    if (t[v].next.count(c))
      t[v].go[c] = t[v].next[c];
    else
      t[v].go[c] = v < 2 ? v : go(get_link(v), c);
  return t[v].go[c];
}
long long der[maxn], rev[maxn];
int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);
  string st, s = "";
  cin >> st;
  int n, m = st.size();
  cin >> n;
  aho_init();
  for (int i = 0; i < int(n); i++) {
    cin >> s;
    add_string(s, 0);
    reverse(s.begin(), s.end());
    add_string(s, 1);
  }
  sort(pos.begin(), pos.end());
  for (auto p : pos) {
    int j = p.second;
    if (t[j].visto) continue;
    t[j].visto = true;
    int l = get_link(j);
    if (l >= 0) {
      t[j].peso += t[l].peso;
    }
  }
  int v = 0;
  for (int i = 0; i < int(m); i++) {
    v = go(v, st[i]);
    der[i] = t[v].peso;
  }
  v = 1;
  for (int i = int(m) - 1; i >= 0; i--) {
    v = go(v, st[i]);
    rev[i] = t[v].peso;
  }
  long long res = 0;
  for (int i = 0; i < int(m - 1); i++) res += der[i] * rev[i + 1];
  cout << res << "\n";
  return 0;
}

```