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("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const long long N = 4e5 + 10;
const long long M = 3e8 + 1;
const long long big = 1e18;
const long long shift = 1000;
const long long hsh2 = 1964325029;
const long long mod = 998244353;
const long double EPS = 1e-14;
const long long block = 700;
string bb;
struct aho {
  long long t[N][26], p[N], k[N], b[N];
  long long c[N][26], tp[N], gl[N] = {0}, rt = 1, cur = 2;
  long long cnt[N] = {0}, sub[N] = {0};
  void add(string a) {
    long long v = rt;
    for (auto u : a) {
      long long c = u - 'a';
      if (!t[v][c])
        p[cur] = v, b[cur] = c, gl[cur] = gl[v] + 1, t[v][c] = cur++;
      v = t[v][c];
    }
    if (a != bb) cnt[v]++;
  }
  void sufsil(long long v) {
    k[v] = c[k[p[v]]][b[v]];
    if (k[v] == v) k[v] = rt;
    tp[v] = tp[k[v]];
    if (cnt[k[v]]) tp[v] = k[v];
    for (int j = 0; j < 26; j++) {
      c[v][j] = c[k[v]][j];
      if (t[v][j]) c[v][j] = t[v][j];
    }
  }
  void bldsuf() {
    k[1] = tp[1] = p[1] = 1;
    for (int i = 0; i < 26; i++) {
      c[1][i] = 1;
      if (t[1][i]) c[1][i] = t[1][i];
    }
    queue<int> q;
    q.push(rt);
    while (q.size()) {
      long long v = q.front();
      q.pop();
      for (int i = 0; i < 26; i++)
        if (t[v][i]) q.push(t[v][i]);
      if (v != 1) sufsil(v);
    }
  }
  string getstr(long long v) {
    string a;
    while (v != rt) a += (char)(b[v] + 'a'), v = p[v];
    reverse((a).begin(), (a).end());
    return a;
  }
  void get(string a) {
    long long v = 1;
    long long ans = 0;
    for (auto u : a) {
      v = t[v][u - 'a'];
      long long to = v;
      while (to != rt) {
        sub[gl[v]] += cnt[to];
        ans += sub[gl[v] - gl[to]] * cnt[to];
        to = tp[to];
      }
    }
    cout << ans << '\n';
  }
} rt;
long long t;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> bb >> t;
  rt.add(bb);
  while (t--) {
    string a;
    cin >> a;
    rt.add(a);
  }
  rt.bldsuf();
  rt.get(bb);
}