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 N = 2e5 + 10;
int n, m, p;
string t, s;
int start[N], fin[N];
long long ans = 0;
template <int A>
struct AhoCorasick {
  struct Vertex {
    int next[A], go[A];
    int parent = -1, link = -1, leaves = 0, count = -1;
    char incoming;
    Vertex(int par = -1, char ch = '$') {
      parent = par;
      incoming = ch;
      fill(next, next + A, -1);
      fill(go, go + A, -1);
    }
  };
  vector<Vertex> trie;
  AhoCorasick() : trie(1) {}
  void add_string(const string &s) {
    int v = 0;
    for (char ch : s) {
      int c = ch - 'a';
      if (trie[v].next[c] == -1) {
        trie[v].next[c] = trie.size();
        trie.emplace_back(v, ch);
      }
      v = trie[v].next[c];
    }
    trie[v].leaves++;
  }
  int get_link(int v) {
    if (trie[v].link == -1) {
      if (v == 0 || trie[v].parent == 0) {
        trie[v].link = 0;
      } else {
        trie[v].link = go(get_link(trie[v].parent), trie[v].incoming);
      }
    }
    return trie[v].link;
  }
  int go(int v, char ch) {
    int c = ch - 'a';
    if (trie[v].go[c] == -1) {
      if (trie[v].next[c] != -1) {
        trie[v].go[c] = trie[v].next[c];
      } else {
        trie[v].go[c] = v == 0 ? 0 : go(get_link(v), ch);
      }
    }
    return trie[v].go[c];
  }
  int count(int v) {
    if (trie[v].count == -1) {
      if (v == 0)
        trie[v].count = 0;
      else {
        trie[v].count = trie[v].leaves + count(get_link(v));
      }
    }
    return trie[v].count;
  }
};
AhoCorasick<26> forw, backw;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> s;
    forw.add_string(s);
    reverse(s.begin(), s.end());
    backw.add_string(s);
  }
  for (int i = 0, v = 0; i < t.length(); i++) {
    v = forw.go(v, t[i]);
    fin[i] = forw.count(v);
  }
  for (int i = t.length() - 1, v = 0; i >= 0; i--) {
    v = backw.go(v, t[i]);
    start[i] = backw.count(v);
  }
  for (int i = 0; i + 1 < t.length(); i++) {
    ans += fin[i] * 1ll * start[i + 1];
  }
  cout << ans << '\n';
  return 0;
}