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;
long long RAND(long long n) { return abs((rand() << 15) + rand()) % n; }
vector<vector<int>> go;
vector<int> out;
vector<int> f;
const int alphabet_size = 26;
void BuildMatchingMachine(vector<string> &arr) {
  int number_of_states = 0;
  for (auto &i : arr) {
    number_of_states += i.size();
  }
  go.resize(number_of_states + 1, vector<int>(alphabet_size, -1));
  out.resize(number_of_states + 1, 0);
  f.resize(number_of_states + 1, -1);
  int node = 1;
  for (int i = 0; i < arr.size(); ++i) {
    int current_node = 0;
    for (int j = 0; j < arr[i].size(); ++j) {
      if (go[current_node][arr[i][j] - 'a'] == -1)
        go[current_node][arr[i][j] - 'a'] = node++;
      current_node = go[current_node][arr[i][j] - 'a'];
    }
    out[current_node]++;
  }
  f[0] = 0;
  queue<int> Init_nodes;
  for (int c = 0; c < alphabet_size; ++c) {
    if (go[0][c] == -1) {
      go[0][c] = 0;
    }
    if (go[0][c] != 0) {
      Init_nodes.push(go[0][c]);
    }
    f[go[0][c]] = 0;
  }
  while (!Init_nodes.empty()) {
    int cur_node = Init_nodes.front();
    Init_nodes.pop();
    for (int c = 0; c < 26; ++c) {
      if (go[cur_node][c] != -1) {
        int failure = f[cur_node];
        while (go[failure][c] == -1) {
          failure = f[failure];
        }
        failure = go[failure][c];
        f[go[cur_node][c]] = failure;
        out[go[cur_node][c]] += out[failure];
        Init_nodes.push(go[cur_node][c]);
      }
    }
  }
}
int FindNextState(int cur_state, char ch) {
  while (go[cur_state][ch - 'a'] == -1) {
    cur_state = f[cur_state];
  }
  return go[cur_state][ch - 'a'];
}
vector<int> Search(vector<string> &pat, string &txt) {
  vector<int> result(txt.size(), 0);
  BuildMatchingMachine(pat);
  int cur_state = 0;
  for (int i = 0; i < (int)txt.size(); ++i) {
    cur_state = FindNextState(cur_state, txt[i]);
    result[i] = out[cur_state];
  }
  go.clear();
  out.clear();
  f.clear();
  return result;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  string t;
  cin >> t;
  int n;
  cin >> n;
  vector<string> str(n);
  for (auto &i : str) {
    cin >> i;
  }
  vector<int> pref = Search(str, t);
  reverse(begin(t), end(t));
  for (auto &i : str) {
    reverse(begin(i), end(i));
  }
  vector<int> suf = Search(str, t);
  long long ans = 0;
  int size = (int)t.size();
  for (int i = 0; i < size - 1; ++i) {
    ans += 1ll * pref[i] * suf[size - i - 2];
  }
  cout << ans;
  return 0;
}