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;
using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
const int nax = 200 * 1000 + 10;
int n, p[nax], beg[nax], e[nax], lim;
string t;
vector<string> s;
int trie[nax][26], finish[nax], nxt = 1, len = 0;
void add(string &q) {
  int node = 0;
  for (auto it : q) {
    if (trie[node][it - 'a'] == 0) {
      node = trie[node][it - 'a'] = nxt;
      nxt++;
    } else {
      node = trie[node][it - 'a'];
    }
  }
  finish[node]++;
}
int cnt_b(int i) {
  int w = 0, node = 0;
  while (i < (int)t.size()) {
    if (trie[node][t[i] - 'a'] == 0) {
      return w;
    } else {
      node = trie[node][t[i] - 'a'];
      w += finish[node];
    }
    i++;
  }
  return w;
}
void kmp(string &q) {
  p[1] = 0;
  for (int i = 2; i <= (int)q.size(); i++) {
    int w = p[i - 1];
    while (w > 0 && q[w] != q[i - 1]) w = p[w];
    if (q[w] == q[i - 1]) w++;
    p[i] = w;
  }
}
void kmpSearch(string &q) {
  int w = 0;
  for (int i = 1; i <= (int)t.size(); i++) {
    while (w > 0 && t[i - 1] != q[w]) w = p[w];
    if (q[w] == t[i - 1]) w++;
    if (w == (int)q.size()) {
      beg[i - (int)q.size() + 1]++;
      e[i]++;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> t >> n;
  for (int i = 0; i < n; i++) {
    string tmp;
    cin >> tmp;
    s.push_back(tmp);
    len += (int)tmp.size();
  }
  lim = sqrt(len);
  for (auto &it : s) {
    if ((int)it.size() > lim) {
      kmp(it);
      kmpSearch(it);
    } else {
      add(it);
    }
    reverse(it.begin(), it.end());
  }
  for (int i = 1; i <= (int)t.size(); i++) {
    beg[i] += cnt_b(i - 1);
  }
  reverse(t.begin(), t.end());
  for (int i = 0; i < nxt; i++) {
    for (int j = 0; j < 26; j++) {
      trie[i][j] = 0;
    }
    finish[i] = 0;
  }
  nxt = 1;
  for (auto &it : s) {
    if ((int)it.size() <= lim) {
      add(it);
    }
  }
  for (int i = 1; i <= (int)t.size(); i++) {
    e[(int)t.size() - i + 1] += cnt_b(i - 1);
  }
  ll ans = 0;
  for (int i = 1; i < (int)t.size(); i++) {
    ans += (ll)e[i] * beg[i + 1];
  }
  cout << ans;
}