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>
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
using namespace std;
const long double eps = 1e-7;
const int inf = 1000000010;
const long long INF = 10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 200010, SGM = 26;
long long n, m, k, u, v, x, y, t, a, b, ans;
long long G[MAXN];
string S[MAXN], T;
int F[MAXN];
int C[MAXN][SGM + 1], ts;
void Add(string s) {
  int node = 0;
  for (char ch : s) {
    if (!C[node][ch - 'a']) C[node][ch - 'a'] = ++ts;
    node = C[node][ch - 'a'];
  }
  C[node][SGM]++;
}
void BuildAho() {
  ts = 0;
  memset(C, 0, sizeof(C));
  memset(F, 0, sizeof(F));
  for (int i = 1; i <= n; i++) Add(S[i]);
  queue<int> Q;
  for (int i = 0; i < SGM; i++)
    if (C[0][i]) Q.push(C[0][i]);
  while (Q.size()) {
    int v = Q.front();
    Q.pop();
    C[v][SGM] += C[F[v]][SGM];
    for (int i = 0; i < SGM; i++) {
      if (!C[v][i])
        C[v][i] = C[F[v]][i];
      else {
        Q.push(C[v][i]);
        F[C[v][i]] = C[F[v]][i];
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> T >> n;
  m = T.size();
  T = "." + T;
  for (int i = 1; i <= n; i++) cin >> S[i];
  BuildAho();
  int v = 0;
  for (int i = 1; i <= m; i++) G[i] = C[v = C[v][T[i] - 'a']][SGM];
  for (int i = 1; i <= n; i++) reverse(S[i].begin(), S[i].end());
  BuildAho();
  v = 0;
  for (int i = m; i; i--) {
    ans += G[i] * C[v][SGM];
    v = C[v][T[i] - 'a'];
  }
  cout << ans << '\n';
  return 0;
}