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 INF = 2e9;
const long long BIG_INF = 1e18;
const long long MOD = 1e9 + 7;
struct node {
  node *next[26];
  long long cnt;
  node() {
    for (int i = 0; i < 26; i++) next[i] = nullptr;
    cnt = 0;
  }
};
const int maxn = 2 * 1e5 + 2;
long long all_cnt[maxn], sm_cnt[maxn];
node *root = new node();
string a[maxn], t;
int pi[2 * maxn];
void add(string s, int in) {
  node *x = root;
  for (int i = 0; i < (int)s.size(); i++) {
    int to = s[i] - 'a';
    if (x->next[to] == nullptr) x->next[to] = new node();
    x = x->next[to];
  }
  x->cnt++;
}
void update(int i, int type) {
  node *x = root;
  int start = i;
  while (i < (int)t.size()) {
    int to = t[i] - 'a';
    if (x->next[to] == nullptr) break;
    x = x->next[to];
    i++;
    if (type)
      all_cnt[start] += x->cnt;
    else
      sm_cnt[i - start] += x->cnt;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  int n;
  cin >> n;
  int lim = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    lim += (int)a[i].size();
  }
  lim = sqrt(lim);
  vector<int> big_in;
  for (int i = 0; i < n; i++) {
    if ((int)a[i].size() <= lim)
      add(a[i], i);
    else
      big_in.push_back(i);
  }
  for (int i = 0; i < (int)t.size(); i++) update(i, 1);
  for (int z = 0; z < (int)big_in.size(); z++) {
    int in = big_in[z];
    string s = a[in] + "#" + t;
    for (int i = 1; i < (int)s.size(); i++) {
      int j = pi[i - 1];
      while (j > 0 && s[i] != s[j]) j = pi[j - 1];
      if (s[i] == s[j]) j++;
      pi[i] = j;
    }
    for (int i = 0; i < (int)s.size(); i++)
      if (pi[i] == (int)a[in].size()) all_cnt[i - 2 * (int)a[in].size()]++;
  }
  long long ans = 0;
  for (int i = 0; i < (int)t.size(); i++) {
    for (int j = 0; j <= lim; j++) sm_cnt[j] = 0;
    update(i, 0);
    for (int j = 1; j <= lim && i + j < (int)t.size(); j++)
      ans += sm_cnt[j] * all_cnt[i + j];
  }
  for (int z = 0; z < (int)big_in.size(); z++) {
    int in = big_in[z];
    string s = a[in] + "#" + t;
    for (int i = 1; i < (int)s.size(); i++) {
      int j = pi[i - 1];
      while (j > 0 && s[i] != s[j]) j = pi[j - 1];
      if (s[i] == s[j]) j++;
      pi[i] = j;
    }
    for (int i = 0; i < (int)s.size(); i++)
      if (pi[i] == (int)a[in].size()) ans += all_cnt[i - (int)a[in].size()];
  }
  cout << ans << "\n";
  return 0;
}