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 M = 2e5 + 10;
const int K = 26;
struct node {
  int par = -1, link = -1, elink = -1;
  char pch;
  bool leaf = false, mark = false;
  int val = 0;
  vector<int> next, go;
  node(int par = -1, char ch = '$')
      : par(par), pch(ch), next(K, -1), go(K, -1) {}
};
class Aho {
 public:
  vector<node> t;
  Aho() { t = vector<node>(1); }
  void add(const string& s) {
    int u = 0;
    for (char ch : s) {
      int c = ch - 'a';
      if (t[u].next[c] < 0) {
        t[u].next[c] = (int)t.size();
        t.emplace_back(u, ch);
      }
      u = t[u].next[c];
    }
    t[u].leaf = true;
    t[u].val++;
  }
  int get_elink(int u) {
    if (t[u].elink < 0) {
      int v = get_link(u);
      if (!u or !v)
        t[u].elink = 0;
      else
        t[u].elink = t[v].leaf ? v : get_elink(v);
    }
    return t[u].elink;
  }
  int get_link(int u) {
    if (t[u].link < 0) {
      t[u].link = (!u or !t[u].par) ? 0 : go(get_link(t[u].par), t[u].pch);
    }
    return t[u].link;
  }
  int go(int u, char ch) {
    int c = ch - 'a';
    if (t[u].go[c] < 0) {
      t[u].go[c] =
          (t[u].next[c] != -1) ? t[u].next[c] : (!u ? 0 : go(get_link(u), ch));
    }
    return t[u].go[c];
  }
  int process(int u) {
    if (t[u].mark) return t[u].val;
    t[u].mark = true;
    return t[u].val += process(get_elink(u));
  }
  void process() {
    for (int u = 0; u < (int)t.size(); ++u) {
      if (!t[u].mark) process(u);
    }
  }
  vector<int> get(const string& s) {
    int n = (int)(s).size(), u = 0;
    vector<int> cnt(n, 0);
    for (int i = 0; i < n; ++i) {
      u = go(u, s[i]);
      cnt[i] = t[u].val;
    }
    return cnt;
  }
};
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  string t;
  cin >> t;
  int n;
  cin >> n;
  string s[n];
  Aho at;
  for (int i = 0; i < n; ++i) cin >> s[i], at.add(s[i]);
  at.process();
  auto cnt = at.get(t);
  Aho atr;
  reverse((t).begin(), (t).end());
  for (int i = 0; i < n; ++i) {
    reverse((s[i]).begin(), (s[i]).end());
    atr.add(s[i]);
  }
  atr.process();
  auto cntr = atr.get(t);
  reverse((cntr).begin(), (cntr).end());
  long long ans = 0;
  n = (int)(cnt).size();
  for (int i = 0; i < n - 1; ++i) ans += cnt[i] * 1ll * cntr[i + 1];
  cout << ans;
  return 0;
}