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 + 100;
struct Node {
  int go[26], nxt[26];
  int cnt;
  int link, par, id;
  Node() {}
  Node(int par, int id) : par(par), id(id) {
    memset(go, -1, sizeof go);
    memset(nxt, -1, sizeof nxt);
    link = -1;
    cnt = 0;
  }
} tree[N];
int nTree;
void Init() {
  tree[0] = Node(-1, -1);
  nTree = 1;
}
void AddString(string st) {
  int p = 0;
  for (char c : st) {
    int id = c - 'a';
    if (tree[p].nxt[id] == -1) {
      tree[nTree] = Node(p, id);
      tree[p].nxt[id] = nTree++;
    }
    p = tree[p].nxt[id];
  }
  tree[p].cnt++;
}
int Go(int u, int id);
int Link(int u) {
  if (tree[u].link == -1) {
    if (u == 0 || tree[u].par == 0)
      tree[u].link = 0;
    else
      tree[u].link = Go(Link(tree[u].par), tree[u].id);
  }
  return tree[u].link;
}
int Go(int u, int id) {
  if (tree[u].go[id] == -1) {
    if (tree[u].nxt[id] != -1)
      tree[u].go[id] = tree[u].nxt[id];
    else {
      if (u == 0)
        tree[u].go[id] = 0;
      else
        tree[u].go[id] = Go(Link(u), id);
    }
  }
  return tree[u].go[id];
}
void BuildValue() {
  queue<int> q;
  q.push(0);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    tree[u].cnt += tree[Link(u)].cnt;
    for (int i = 0; i < 26; ++i)
      if (tree[u].nxt[i] != -1) q.push(tree[u].nxt[i]);
  }
}
int f[N];
void Calc(string t) {
  int p = 0;
  int i = 0;
  for (char c : t) {
    int id = c - 'a';
    p = Go(p, id);
    f[i++] = tree[p].cnt;
  }
}
string s[N];
int Left[N], Right[N];
int main() {
  string t;
  int n;
  cin >> t >> n;
  for (int i = 0; i < n; ++i) cin >> s[i];
  Init();
  for (int i = 0; i < n; ++i) AddString(s[i]);
  BuildValue();
  Calc(t);
  for (int i = 0; i < t.size(); ++i) Left[i] = f[i];
  reverse(t.begin(), t.end());
  Init();
  for (int i = 0; i < n; ++i) {
    reverse(s[i].begin(), s[i].end());
    AddString(s[i]);
  }
  BuildValue();
  Calc(t);
  for (int i = 0; i < t.size(); ++i) Right[i] = f[t.size() - i - 1];
  long long ans = 0;
  for (int i = 0; i < (int)t.size() - 1; ++i) {
    ans += 1ll * Left[i] * Right[i + 1];
  }
  cout << ans;
}