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 MAXN = 2e5 + 10;
const int MAXC = 26;
int base = 'a';
struct aho_corasick {
  int N, cnt = 0;
  vector<vector<int>> T;
  vector<long long> term, fail;
  aho_corasick() {}
  aho_corasick(int N) : N(N), cnt(0) {
    T.resize(N, vector<int>(MAXC, 0));
    term.resize(N, 0LL);
    fail.resize(N, 0LL);
  }
  void insert(string x) {
    int pos = 0;
    for (int i = 0; i < x.size(); i++) {
      if (T[pos][x[i] - base] == 0) T[pos][x[i] - base] = ++cnt;
      pos = T[pos][x[i] - base];
    }
    term[pos]++;
  }
  void make_failure() {
    queue<int> Q;
    for (int i = 0; i < MAXC; i++)
      if (T[0][i]) Q.push(T[0][i]);
    while (Q.size()) {
      int here = Q.front();
      Q.pop();
      for (int i = 0; i < MAXC; i++)
        if (T[here][i]) {
          int pos = fail[here], there = T[here][i];
          while (pos && T[pos][i] == 0) pos = fail[pos];
          fail[there] = T[pos][i];
          term[there] += term[T[pos][i]];
          Q.push(there);
        }
    }
  }
};
string S;
int N;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin >> S;
  aho_corasick aho1 = aho_corasick(MAXN), aho2 = aho_corasick(MAXN);
  cin >> N;
  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    aho1.insert(s);
    reverse(s.begin(), s.end());
    aho2.insert(s);
  }
  aho1.make_failure();
  aho2.make_failure();
  int pos = 0;
  vector<long long> D1 = vector<long long>(S.size(), 0LL);
  for (int i = 0; i < S.size(); i++) {
    while (pos && aho1.T[pos][S[i] - base] == 0) pos = aho1.fail[pos];
    pos = aho1.T[pos][S[i] - base];
    D1[i] = aho1.term[pos];
  }
  pos = 0;
  vector<long long> D2 = vector<long long>(S.size(), 0LL);
  for (int i = S.size() - 1; i >= 0; i--) {
    while (pos && aho2.T[pos][S[i] - base] == 0) pos = aho2.fail[pos];
    pos = aho2.T[pos][S[i] - base];
    D2[i] = aho2.term[pos];
  }
  long long ans = 0;
  for (int i = 0; i + 1 < S.size(); i++) ans += D1[i] * D2[i + 1];
  cout << ans << '\n';
  return 0;
}