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 MX = 300000;
const int chr = 26;
struct node {
  int nxt[chr];
  node() { memset(nxt, -1, sizeof(nxt)); }
};
node T[MX];
int suffix[MX], indx, len, path[MX];
int val[MX], ed[MX];
int E[MX], esf[MX];
long long A[MX], B[MX];
struct Aho_Corasick {
  void init() {
    memset(E, 0, sizeof(E));
    len = indx = 0;
    memset(T, 0, sizeof(T));
    memset(suffix, 0, sizeof(suffix));
    T[indx] = node();
  }
  void insert(string s, int p) {
    int now = 0;
    for (int i = 0; i < s.size(); i++) {
      int id = s[i] - 'a';
      if (T[now].nxt[id] == -1) {
        T[now].nxt[id] = ++indx;
        T[indx] = node();
      }
      now = T[now].nxt[id];
    }
    ed[p] = now;
    E[now]++;
  }
  void reverse_link() {
    queue<int> q;
    for (int i = 0; i < chr; i++) {
      if (T[0].nxt[i] != -1) {
        q.push(T[0].nxt[i]);
      } else
        T[0].nxt[i] = 0;
    }
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      for (int i = 0; i < chr; i++) {
        int v = T[u].nxt[i];
        if (v == -1) {
          T[u].nxt[i] = T[suffix[u]].nxt[i];
          continue;
        }
        suffix[v] = T[suffix[u]].nxt[i];
        q.push(v);
        path[len++] = v;
        E[v] += E[suffix[v]];
      }
    }
  }
  void search(string s, int t) {
    int now = 0;
    for (int i = 0; i < s.size(); i++) {
      int id = s[i] - 'a';
      now = T[now].nxt[id];
      if (t == 0)
        A[i] = E[now];
      else
        B[i] = E[now];
    }
  }
} AC;
string s[MX];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string txt;
  int n;
  cin >> txt >> n;
  AC.init();
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
    AC.insert(s[i], i);
  }
  AC.reverse_link();
  AC.search(txt, 0);
  AC.init();
  for (int i = 1; i <= n; i++) {
    reverse(s[i].begin(), s[i].end());
    AC.insert(s[i], i);
  }
  AC.reverse_link();
  reverse(txt.begin(), txt.end());
  AC.search(txt, 1);
  long long ans = 0, sz = txt.size();
  for (int i = 0; i < sz - 1; i++) {
    ans += A[i] * B[sz - i - 2];
  }
  cout << ans << endl;
  return 0;
}