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;
template <class T>
int chkmax(T& a, T b) {
  if (b > a) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
int chkmin(T& a, T b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <class iterator>
void output(iterator begin, iterator end, ostream& out = cerr) {
  while (begin != end) {
    out << (*begin) << " ";
    begin++;
  }
  out << endl;
}
template <class T>
void output(T x, ostream& out = cerr) {
  output(x.begin(), x.end(), out);
}
void fast_io() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
const int MX = 1e6 + 228;
const int K = 26;
int ptr, go[MX][K], link[MX], term[MX];
void init() {
  for (int i = 0; i < MX; ++i) {
    term[i] = 0;
    for (int j = 0; j < K; ++j) {
      go[i][j] = -1;
    }
  }
  ptr = 1;
}
void add_to_trie(string s) {
  int v = 0;
  for (int i = 0; i < s.size(); ++i) {
    int ch = s[i] - 'a';
    if (go[v][ch] == -1) {
      go[v][ch] = ptr++;
    }
    v = go[v][ch];
  }
  term[v]++;
}
void bfs() {
  queue<int> q;
  q.push(0);
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (int i = 0; i < K; ++i) {
      if (go[v][i] == -1) {
        go[v][i] = (v == 0 ? 0 : go[link[v]][i]);
      } else {
        link[go[v][i]] = (v == 0 ? 0 : go[link[v]][i]);
        q.push(go[v][i]);
      }
    }
    term[v] += term[link[v]];
  }
}
const int mx = 2e5 + 228;
string t;
int n, len, pref[mx], suf[mx];
vector<string> S;
signed main() {
  fast_io();
  cin >> t;
  len = t.size();
  init();
  cin >> n;
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    S.push_back(s);
    add_to_trie(s);
  }
  bfs();
  int v = 0;
  for (int i = 0; i < len; ++i) {
    v = go[v][t[i] - 'a'];
    pref[i] = term[v];
  }
  init();
  for (int i = 0; i < n; ++i) {
    reverse(S[i].begin(), S[i].end());
    add_to_trie(S[i]);
  }
  bfs();
  v = 0;
  for (int i = len - 1; i >= 0; --i) {
    v = go[v][t[i] - 'a'];
    suf[i] = term[v];
  }
  long long ans = 0;
  for (int i = 0; i < len - 1; ++i) {
    ans += (long long)pref[i] * (long long)suf[i + 1];
  }
  cout << ans << endl;
}