#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &x) {
  x = 0;
  int f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -f;
  for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
  x *= f;
}
template <typename T>
void chkmax(T &x, T y) {
  x = max(x, y);
}
template <typename T>
void chkmin(T &x, T y) {
  x = min(x, y);
}
const int N = 200005;
struct AC_Aautomaton {
  struct Trie {
    int ed, fl, c[26];
  };
  Trie t[N];
  int cnt;
  queue<int> q;
  vector<int> son[N];
  int dp[N], val[N];
  void Build_Trie(string s) {
    int len = s.length(), now = 0;
    for (int i = 0, v; i < len; ++i) {
      v = s[i] - 'a';
      if (!t[now].c[v]) t[now].c[v] = ++cnt;
      now = t[now].c[v];
    }
    t[now].ed++;
  }
  void Build_Fail() {
    for (int i = 0; i < 26; ++i)
      if (t[0].c[i]) q.push(t[0].c[i]);
    int u, v;
    while (!q.empty()) {
      u = q.front();
      q.pop();
      for (int i = 0; i < 26; ++i)
        if (v = t[u].c[i])
          t[v].fl = t[t[u].fl].c[i], q.push(v);
        else
          t[u].c[i] = t[t[u].fl].c[i];
    }
    for (int i = 1; i <= cnt; ++i) son[t[i].fl].push_back(i);
  }
  void Dfs(int u) {
    dp[u] += t[u].ed;
    for (int i = 0, v; i < son[u].size(); ++i)
      dp[v = son[u][i]] += dp[u], Dfs(v);
  }
  void Query(string s) {
    int len = s.length(), now = 0;
    for (int i = 0, v; i < len; ++i) {
      v = s[i] - 'a';
      now = t[now].c[v];
      val[i] = dp[now];
    }
  }
} S, E;
string t, s;
int n;
long long ans;
int main() {
  cin >> t >> n;
  for (int i = 1; i <= n; ++i)
    cin >> s, S.Build_Trie(s), reverse(s.begin(), s.end()), E.Build_Trie(s);
  S.Build_Fail(), E.Build_Fail();
  S.Dfs(0), E.Dfs(0);
  S.Query(t), reverse(t.begin(), t.end()), E.Query(t);
  for (int i = 0, len = t.length(); i < len - 1; ++i)
    ans += 1ll * S.val[i] * E.val[len - i - 2];
  cout << ans << '\n';
  return 0;
}

### Prompt

Please formulate a cpp solution to the following 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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &x) {
  x = 0;
  int f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -f;
  for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
  x *= f;
}
template <typename T>
void chkmax(T &x, T y) {
  x = max(x, y);
}
template <typename T>
void chkmin(T &x, T y) {
  x = min(x, y);
}
const int N = 200005;
struct AC_Aautomaton {
  struct Trie {
    int ed, fl, c[26];
  };
  Trie t[N];
  int cnt;
  queue<int> q;
  vector<int> son[N];
  int dp[N], val[N];
  void Build_Trie(string s) {
    int len = s.length(), now = 0;
    for (int i = 0, v; i < len; ++i) {
      v = s[i] - 'a';
      if (!t[now].c[v]) t[now].c[v] = ++cnt;
      now = t[now].c[v];
    }
    t[now].ed++;
  }
  void Build_Fail() {
    for (int i = 0; i < 26; ++i)
      if (t[0].c[i]) q.push(t[0].c[i]);
    int u, v;
    while (!q.empty()) {
      u = q.front();
      q.pop();
      for (int i = 0; i < 26; ++i)
        if (v = t[u].c[i])
          t[v].fl = t[t[u].fl].c[i], q.push(v);
        else
          t[u].c[i] = t[t[u].fl].c[i];
    }
    for (int i = 1; i <= cnt; ++i) son[t[i].fl].push_back(i);
  }
  void Dfs(int u) {
    dp[u] += t[u].ed;
    for (int i = 0, v; i < son[u].size(); ++i)
      dp[v = son[u][i]] += dp[u], Dfs(v);
  }
  void Query(string s) {
    int len = s.length(), now = 0;
    for (int i = 0, v; i < len; ++i) {
      v = s[i] - 'a';
      now = t[now].c[v];
      val[i] = dp[now];
    }
  }
} S, E;
string t, s;
int n;
long long ans;
int main() {
  cin >> t >> n;
  for (int i = 1; i <= n; ++i)
    cin >> s, S.Build_Trie(s), reverse(s.begin(), s.end()), E.Build_Trie(s);
  S.Build_Fail(), E.Build_Fail();
  S.Dfs(0), E.Dfs(0);
  S.Query(t), reverse(t.begin(), t.end()), E.Query(t);
  for (int i = 0, len = t.length(); i < len - 1; ++i)
    ans += 1ll * S.val[i] * E.val[len - i - 2];
  cout << ans << '\n';
  return 0;
}

```