#include <bits/stdc++.h>
using namespace std;
const long long mod = 2147481811, k = 233, inv = 138249902;
template <typename T>
void read(T &x) {
  int f = 1;
  x = 0;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -f;
  for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
  x *= f;
}
unordered_map<long long, int> S;
unordered_set<long long> SS[205];
string t, s[200005];
int n, f[200005], g[200005], nxt[200005], l[200005], L, sz = 200, p;
long long ans = 0, hs[200005], P[200005], IP[200005], x;
inline long long Get(const int &l, const int &r) {
  return IP[l - 1] * (hs[r] - hs[l - 1] + mod) % mod;
}
int main() {
  ios::sync_with_stdio(0);
  cin >> t;
  L = t.length();
  t = '*' + t;
  cin >> n;
  P[0] = IP[0] = 1;
  for (int i = 1; i <= 200000; ++i)
    P[i] = P[i - 1] * k % mod, IP[i] = IP[i - 1] * inv % mod;
  for (int i = 1; i <= n; ++i)
    cin >> s[i], l[i] = s[i].length(), s[i] = '*' + s[i];
  for (int i = 1; i <= n; ++i) {
    if (l[i] > sz) continue;
    long long Hs = 0;
    for (int j = 1; j <= l[i]; ++j) Hs = (Hs + P[j - 1] * s[i][j]) % mod;
    ++S[Hs];
    SS[l[i]].insert(Hs);
  }
  for (int i = 1; i <= L; ++i) hs[i] = (hs[i - 1] + P[i - 1] * t[i]) % mod;
  for (int i = 0; i < sz; ++i)
    for (int j = 1; j + i <= L; ++j) {
      x = Get(j, j + i);
      if (!SS[i + 1].count(x)) continue;
      p = S[Get(j, j + i)];
      f[j] += p;
      g[j + i] += p;
    }
  for (int i = 1; i <= n; ++i) {
    if (l[i] <= sz) continue;
    p = 0;
    for (int j = 2; j <= l[i]; ++j) {
      for (; p && s[i][p + 1] != s[i][j]; p = nxt[p])
        ;
      if (s[i][p + 1] == s[i][j]) ++p;
      nxt[j] = p;
    }
    p = 0;
    for (int j = 1; j <= L; ++j) {
      for (; p && s[i][p + 1] != t[j]; p = nxt[p])
        ;
      if (p < l[i] && s[i][p + 1] == t[j]) ++p;
      if (p == l[i]) ++g[j], ++f[j - l[i] + 1];
    }
  }
  for (int i = 1; i < L; ++i) ans += 1ll * g[i] * f[i + 1];
  cout << ans << '\n';
  return 0;
}

### Prompt

In Cpp, your task is to solve 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;
const long long mod = 2147481811, k = 233, inv = 138249902;
template <typename T>
void read(T &x) {
  int f = 1;
  x = 0;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -f;
  for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
  x *= f;
}
unordered_map<long long, int> S;
unordered_set<long long> SS[205];
string t, s[200005];
int n, f[200005], g[200005], nxt[200005], l[200005], L, sz = 200, p;
long long ans = 0, hs[200005], P[200005], IP[200005], x;
inline long long Get(const int &l, const int &r) {
  return IP[l - 1] * (hs[r] - hs[l - 1] + mod) % mod;
}
int main() {
  ios::sync_with_stdio(0);
  cin >> t;
  L = t.length();
  t = '*' + t;
  cin >> n;
  P[0] = IP[0] = 1;
  for (int i = 1; i <= 200000; ++i)
    P[i] = P[i - 1] * k % mod, IP[i] = IP[i - 1] * inv % mod;
  for (int i = 1; i <= n; ++i)
    cin >> s[i], l[i] = s[i].length(), s[i] = '*' + s[i];
  for (int i = 1; i <= n; ++i) {
    if (l[i] > sz) continue;
    long long Hs = 0;
    for (int j = 1; j <= l[i]; ++j) Hs = (Hs + P[j - 1] * s[i][j]) % mod;
    ++S[Hs];
    SS[l[i]].insert(Hs);
  }
  for (int i = 1; i <= L; ++i) hs[i] = (hs[i - 1] + P[i - 1] * t[i]) % mod;
  for (int i = 0; i < sz; ++i)
    for (int j = 1; j + i <= L; ++j) {
      x = Get(j, j + i);
      if (!SS[i + 1].count(x)) continue;
      p = S[Get(j, j + i)];
      f[j] += p;
      g[j + i] += p;
    }
  for (int i = 1; i <= n; ++i) {
    if (l[i] <= sz) continue;
    p = 0;
    for (int j = 2; j <= l[i]; ++j) {
      for (; p && s[i][p + 1] != s[i][j]; p = nxt[p])
        ;
      if (s[i][p + 1] == s[i][j]) ++p;
      nxt[j] = p;
    }
    p = 0;
    for (int j = 1; j <= L; ++j) {
      for (; p && s[i][p + 1] != t[j]; p = nxt[p])
        ;
      if (p < l[i] && s[i][p + 1] == t[j]) ++p;
      if (p == l[i]) ++g[j], ++f[j - l[i] + 1];
    }
  }
  for (int i = 1; i < L; ++i) ans += 1ll * g[i] * f[i + 1];
  cout << ans << '\n';
  return 0;
}

```