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, SQ = sqrt(N), A = 26;
struct node {
  int ctr;
  node* ch[A];
};
string s[N];
long long solve(string t, int n);
vector<int> compute_Z(string s);
void trie_insert(node* root, string s);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string t;
  int n;
  cin >> t >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> s[i];
  }
  cout << solve(t, n) << '\n';
}
long long solve(string t, int n) {
  int m = t.length();
  vector<long long> fw(m, 0), bw(m, 0);
  node* root = new node();
  for (int i = 1; i <= n; ++i) {
    int len = s[i].length();
    if (len < SQ) {
      trie_insert(root, s[i]);
    } else {
      vector<int> zf = compute_Z(s[i] + "$" + t);
      for (int j = len + 1; j <= m + 1; ++j) {
        if (zf[j] == len) {
          ++fw[j - len - 1];
          ++bw[j - 2];
        }
      }
    }
  }
  for (int i = 0; i < m; ++i) {
    node* cur = root;
    for (int j = i; j < m; ++j) {
      if (!cur->ch[t[j] - 'a']) {
        break;
      }
      cur = cur->ch[t[j] - 'a'];
      fw[i] += cur->ctr;
      bw[j] += cur->ctr;
    }
  }
  long long ans = 0;
  for (int i = 0; i < m - 1; ++i) {
    ans += bw[i] * fw[i + 1];
  }
  return ans;
}
vector<int> compute_Z(string s) {
  int n = s.length();
  vector<int> z(n, 0);
  z[0] = n;
  int l = 0, r = 0;
  for (int i = 1; i < n; ++i) {
    if (r >= i) {
      z[i] = min(z[i - l], r - i + 1);
    }
    while (i + z[i] < n and s[i + z[i]] == s[z[i]]) {
      ++z[i];
    }
    if (i + z[i] - 1 > r) {
      r = i + z[i] - 1;
      l = i;
    }
  }
  return z;
}
void trie_insert(node* root, string s) {
  for (auto& c : s) {
    if (root->ch[c - 'a'] == NULL) {
      root->ch[c - 'a'] = new node();
    }
    root = root->ch[c - 'a'];
  }
  ++root->ctr;
}