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 = 200005;
const int K = 26;
int n, ptr, nxt[N][K], val[N], link[N];
long long fcnt[N], bcnt[N];
string s;
inline void clear() {
  for (int i = 0; i < K; i++) {
    nxt[ptr][i] = -1;
  }
  val[ptr] = 0;
}
inline void insert(string &t) {
  int rt = 0;
  int m = t.size();
  for (int i = 0; i < m; i++) {
    int ch = t[i] - 'a';
    if (nxt[rt][ch] == -1) {
      clear();
      nxt[rt][ch] = ptr++;
    }
    rt = nxt[rt][ch];
  }
  val[rt]++;
}
inline void add_links() {
  queue<int> q;
  link[0] = 0;
  for (int i = 0; i < K; i++) {
    if (nxt[0][i] != -1) {
      link[nxt[0][i]] = 0;
      q.push(nxt[0][i]);
    } else {
      nxt[0][i] = 0;
    }
  }
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (int i = 0; i < K; i++) {
      if (nxt[v][i] == -1) continue;
      int u = link[v];
      while (u != 0) {
        if (nxt[u][i] != -1) break;
        u = link[u];
      }
      link[nxt[v][i]] = nxt[u][i];
      q.push(nxt[v][i]);
    }
  }
}
inline void run(int len) {
  int rt = 0;
  for (int i = 0; i < n; i++) {
    int ch = s[i] - 'a';
    while (nxt[rt][ch] == -1) rt = link[rt];
    rt = nxt[rt][ch];
    bcnt[i] += val[rt];
    if (i - len + 1 >= 0) fcnt[i - len + 1] += val[rt];
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << setprecision(32);
  cin >> s;
  n = s.size();
  int m;
  cin >> m;
  vector<string> t(m);
  for (int i = 0; i < m; i++) {
    cin >> t[i];
  }
  sort(t.begin(), t.end(),
       [&](string &a, string &b) { return a.size() < b.size(); });
  memset(fcnt, 0, sizeof(fcnt));
  memset(bcnt, 0, sizeof(bcnt));
  ptr = 0;
  for (int i = 0; i < m; i++) {
    int j = i;
    while (j + 1 < m && t[j + 1].size() == t[i].size()) j++;
    while (ptr >= 0) {
      clear();
      ptr--;
    }
    ptr = 1;
    for (int k = i; k <= j; k++) {
      insert(t[k]);
    }
    add_links();
    run(t[i].size());
    i = j;
  }
  long long ans = 0;
  for (int i = 1; i < n; i++) {
    ans += fcnt[i] * bcnt[i - 1];
  }
  cout << ans << endl;
  return 0;
}