#include <bits/stdc++.h>
using namespace std;
struct custom_hash {
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return x + FIXED_RANDOM;
  }
};
int pw[300005];
int hs[300005];
set<int> lens;
unordered_map<int, int, custom_hash> mp[300005];
int get(int l, int r) {
  long long ans = hs[r] - 1LL * hs[l - 1] * pw[r - l + 1];
  ans %= 1000000009;
  if (ans < 0) ans += 1000000009;
  return ans;
}
int tot[300005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  pw[0] = 1;
  for (int i = 1; i < 300005; i++) pw[i] = (pw[i - 1] * 37LL) % 1000000009;
  string t;
  cin >> t;
  t = '#' + t;
  hs[0] = 0;
  for (int i = 1; i < t.size(); i++) {
    hs[i] = (hs[i - 1] * 37LL + (t[i] - 'a')) % 1000000009;
  }
  int n;
  cin >> n;
  string s;
  while (n--) {
    cin >> s;
    int now = 0;
    for (auto u : s) {
      now = (now * 37LL + (u - 'a')) % 1000000009;
    }
    mp[s.size()][now]++;
    lens.insert(s.size());
  }
  long long ans = 0;
  vector<int> temp;
  for (int u : lens) temp.push_back(u);
  for (int i = t.size() - 1; i >= 1; i--) {
    for (int len : temp) {
      int how = 0;
      int what = get(i, i + len - 1);
      if (i + len - 1 < t.size() && mp[len].count(what)) {
        how = mp[len].at(what);
      }
      if (i + len < t.size()) {
        ans += 1LL * tot[i + len] * how;
      }
      tot[i] += how;
    }
  }
  cout << ans;
}

### Prompt

Generate 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;
struct custom_hash {
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return x + FIXED_RANDOM;
  }
};
int pw[300005];
int hs[300005];
set<int> lens;
unordered_map<int, int, custom_hash> mp[300005];
int get(int l, int r) {
  long long ans = hs[r] - 1LL * hs[l - 1] * pw[r - l + 1];
  ans %= 1000000009;
  if (ans < 0) ans += 1000000009;
  return ans;
}
int tot[300005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  pw[0] = 1;
  for (int i = 1; i < 300005; i++) pw[i] = (pw[i - 1] * 37LL) % 1000000009;
  string t;
  cin >> t;
  t = '#' + t;
  hs[0] = 0;
  for (int i = 1; i < t.size(); i++) {
    hs[i] = (hs[i - 1] * 37LL + (t[i] - 'a')) % 1000000009;
  }
  int n;
  cin >> n;
  string s;
  while (n--) {
    cin >> s;
    int now = 0;
    for (auto u : s) {
      now = (now * 37LL + (u - 'a')) % 1000000009;
    }
    mp[s.size()][now]++;
    lens.insert(s.size());
  }
  long long ans = 0;
  vector<int> temp;
  for (int u : lens) temp.push_back(u);
  for (int i = t.size() - 1; i >= 1; i--) {
    for (int len : temp) {
      int how = 0;
      int what = get(i, i + len - 1);
      if (i + len - 1 < t.size() && mp[len].count(what)) {
        how = mp[len].at(what);
      }
      if (i + len < t.size()) {
        ans += 1LL * tot[i + len] * how;
      }
      tot[i] += how;
    }
  }
  cout << ans;
}

```