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 maxN = 200005;
struct AHO {
  int nxt[26], go[26];
  int suf_link;
  int p;
  char p_chr;
  vector<int> links;
  int cnt_end;
  int cnt_suf;
  AHO(int a = -1, char b = '$') : p(a), p_chr(b) {
    fill(begin(nxt), end(nxt), -1);
    fill(begin(go), end(go), -1);
    cnt_end = cnt_suf = 0;
    suf_link = -1;
  }
};
int N, C[maxN];
string T;
vector<AHO> trie(1), rev_trie(1);
void add_string(vector<AHO>& t, const string& s) {
  int v = 0, c;
  for (char ch : s) {
    c = ch - 'a';
    if (t[v].nxt[c] == -1) {
      t[v].nxt[c] = (int)t.size();
      t.emplace_back(v, ch);
    }
    v = t[v].nxt[c];
  }
  ++t[v].cnt_suf;
  ++t[v].cnt_end;
}
int go(vector<AHO>&, int, char);
int get_suf_link(vector<AHO>& t, int v) {
  if (t[v].suf_link == -1) {
    if (v == 0 || t[v].p == 0)
      t[v].suf_link = 0;
    else
      t[v].suf_link = go(t, get_suf_link(t, t[v].p), t[v].p_chr);
    t[t[v].suf_link].links.push_back(v);
  }
  return t[v].suf_link;
}
int go(vector<AHO>& t, int v, char ch) {
  int c = ch - 'a';
  if (t[v].go[c] == -1) {
    if (t[v].nxt[c] != -1)
      t[v].go[c] = t[v].nxt[c];
    else if (v == 0)
      t[v].go[c] = 0;
    else
      t[v].go[c] = go(t, get_suf_link(t, v), ch);
  }
  return t[v].go[c];
}
void build_suf_tree(vector<AHO>& t) {
  for (int i = 0; i < (int)t.size(); ++i) get_suf_link(t, i);
}
void dfs(vector<AHO>& t, int v = 0, int cnt = 0) {
  cnt += t[v].cnt_suf;
  t[v].cnt_suf = cnt;
  for (int x : t[v].links) {
    if (x == v) continue;
    dfs(t, x, cnt);
  }
}
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin >> T >> N;
  for (int i = 0; i < N; ++i) {
    string s;
    cin >> s;
    add_string(trie, s);
    reverse(s.begin(), s.end());
    add_string(rev_trie, s);
  }
  build_suf_tree(trie);
  build_suf_tree(rev_trie);
  dfs(trie);
  dfs(rev_trie);
  N = (int)T.size();
  int v = 0;
  for (int i = N - 1; i >= 0; --i) {
    v = go(rev_trie, v, T[i]);
    C[i] += rev_trie[v].cnt_suf;
  }
  long long ans = 0;
  v = 0;
  for (int i = 0; i < N; ++i) {
    v = go(trie, v, T[i]);
    ans += (long long)(trie[v].cnt_suf) * C[i + 1];
  }
  printf("%lld\n", ans);
  return 0;
}