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;
struct node {
  node() { occ = 0; }
  int occ;
  map<char, node *> edge;
};
const int MAX_N = 2e5 + 5;
string t, s[MAX_N];
int n, sumlen;
node *trie;
int suf[MAX_N], pref[MAX_N], kmp[MAX_N];
void calcKMP(string str) {
  int len = 0;
  kmp[0] = 0;
  int M = str.length();
  int i = 1;
  while (i < M) {
    if (str[i] == str[len]) {
      kmp[i++] = ++len;
    } else if (len == 0) {
      kmp[i++] = 0;
    } else {
      len = kmp[len - 1];
    }
  }
}
void solve(int *arr) {
  int N = t.length();
  fill(arr, arr + N, 0);
  trie = new node();
  for (int i = 0; i < n; i++) {
    int len = s[i].length();
    if (len * len < sumlen) {
      node *p = trie;
      for (int j = 0; j < len; j++) {
        if (p->edge.count(s[i][j]) == 0) {
          node *q = new node();
          p->edge[s[i][j]] = q;
          p = q;
        } else {
          p = p->edge[s[i][j]];
        }
      }
      p->occ++;
    } else {
      calcKMP(s[i]);
      int j = 0, k = 0;
      while (j < N) {
        if (s[i][k] == t[j]) {
          j++;
          k++;
        }
        if (k == len) {
          arr[j - k]++;
          k = kmp[k - 1];
        } else if (j < N && s[i][k] != t[j]) {
          if (k == 0) {
            j++;
          } else {
            k = kmp[k - 1];
          }
        }
      }
    }
  }
  for (int i = 0; i < N; i++) {
    node *p = trie;
    int j = i;
    while (j < N && p->edge.count(t[j])) {
      p = p->edge[t[j]];
      arr[i] += p->occ;
      j++;
    }
  }
}
string reverse(string s) {
  string res = "";
  int len = s.length();
  for (int i = len - 1; i >= 0; i--) {
    res.push_back(s[i]);
  }
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> t >> n;
  long long f = 0;
  int N = t.length();
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    sumlen += s[i].length();
  }
  solve(suf);
  t = reverse(t);
  for (int i = 0; i < n; i++) {
    s[i] = reverse(s[i]);
  }
  solve(pref);
  long long num = 0;
  for (int i = 0; i < N - 1; i++) {
    num += ((long long)pref[N - i - 1]) * ((long long)suf[i + 1]);
  }
  cout << num << endl;
}