#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 1;
inline int gt(int x, int n) {
  while (x >= n) x -= n;
  return x;
}
vector<int> magic(string &s) {
  int n = s.size(), LOG = ceil(log2(n)), lst = 0, cnt = 0;
  vector<int> p(n), c(n), cc(n);
  {
    vector<int> alf(27);
    for (auto &i : s) alf[i - 'a' + 1] = 1;
    for (int j = 0; j < 27; ++j)
      if (alf[j]) alf[j] = cnt++;
    for (int j = 0; j < n; ++j) c[j] = alf[s[j] - 'a' + 1];
  }
  for (int j = 0; j < LOG; ++j) {
    vector<vector<int> > fr(n), sc(n);
    for (int i = 0; i < n; ++i) {
      fr[c[gt(i + (1 << j), n)]].push_back(i);
    }
    for (auto f : fr)
      for (int z : f) sc[c[z]].push_back(z);
    int curr = 0, clas = 0;
    for (int f = 0; f < n; ++f) {
      if (sc[f].empty()) break;
      int prev = sc[f][0];
      for (int i = 0; i < sc[f].size(); ++i) {
        if (make_pair(c[prev], c[gt(prev + (1 << j), n)]) !=
            make_pair(c[sc[f][i]], c[gt(sc[f][i] + (1 << j), n)]))
          clas++;
        cc[sc[f][i]] = clas;
        if (j == LOG - 1) p[lst++] = sc[f][i];
        prev = sc[f][i];
      }
      ++clas;
    }
    swap(c, cc);
  }
  return p;
}
vector<string> all;
char chek(string a, string b) {
  for (int j = 0; j < min(a.size(), b.size()); ++j) {
    if (a[j] > b[j]) return 1;
    if (a[j] < b[j]) return 2;
  }
  if (a.size() > b.size()) return 1;
  if (b.size() > a.size()) return 2;
  return 0;
}
vector<int> solve(string t, bool dbg) {
  t += char('a' - 1);
  vector<int> perm = magic(t);
  vector<int> delta(t.size() + 1);
  for (int j = 0; j < all.size(); ++j) {
    int l = 0, r = t.size() - 1;
    while (l != r) {
      int mid = (l + r) >> 1;
      string curr;
      for (int f = perm[mid]; f < min(t.size(), perm[mid] + all[j].size()); ++f)
        curr += t[f];
      if (chek(curr, all[j]) == 1) {
        r = mid;
      } else {
        if (l + 1 == r)
          l = r;
        else
          l = mid;
      }
    }
    if (chek(t.substr(perm[r], min(all[j].size(), t.size() - perm[r])),
             all[j]) == 0)
      ++r;
    int R = r;
    l = 0, r = t.size() - 1;
    while (l != r) {
      int mid = (l + r) >> 1;
      string curr;
      for (int f = perm[mid]; f < min(t.size(), perm[mid] + all[j].size()); ++f)
        curr += t[f];
      if (chek(curr, all[j]) == 2) {
        if (l + 1 == r)
          l = r;
        else
          l = mid;
      } else {
        r = mid;
      }
    }
    if (chek(t.substr(perm[r], min(all[j].size(), t.size() - perm[r])),
             all[j]) == 0) {
      delta[r]++, delta[R]--;
    }
  }
  int curr = 0;
  vector<int> answer(t.size());
  for (int j = 0; j < t.size(); ++j) {
    curr += delta[j];
    answer[perm[j]] = curr;
  }
  return answer;
}
signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  string t;
  int n;
  cin >> t >> n;
  all.resize(n);
  for (int j = 0; j < n; ++j) {
    cin >> all[j];
  }
  vector<int> first = solve(t, 0);
  first.pop_back();
  reverse(t.begin(), t.end());
  for (auto &i : all) reverse(i.begin(), i.end());
  vector<int> second = solve(t, 0);
  second.pop_back();
  reverse(second.begin(), second.end());
  long long ans = 0;
  for (int z = 1; z < t.size(); ++z) {
    ans += 1ll * second[z - 1] * first[z];
  }
  cout << ans;
  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 int maxn = 2e5 + 1;
inline int gt(int x, int n) {
  while (x >= n) x -= n;
  return x;
}
vector<int> magic(string &s) {
  int n = s.size(), LOG = ceil(log2(n)), lst = 0, cnt = 0;
  vector<int> p(n), c(n), cc(n);
  {
    vector<int> alf(27);
    for (auto &i : s) alf[i - 'a' + 1] = 1;
    for (int j = 0; j < 27; ++j)
      if (alf[j]) alf[j] = cnt++;
    for (int j = 0; j < n; ++j) c[j] = alf[s[j] - 'a' + 1];
  }
  for (int j = 0; j < LOG; ++j) {
    vector<vector<int> > fr(n), sc(n);
    for (int i = 0; i < n; ++i) {
      fr[c[gt(i + (1 << j), n)]].push_back(i);
    }
    for (auto f : fr)
      for (int z : f) sc[c[z]].push_back(z);
    int curr = 0, clas = 0;
    for (int f = 0; f < n; ++f) {
      if (sc[f].empty()) break;
      int prev = sc[f][0];
      for (int i = 0; i < sc[f].size(); ++i) {
        if (make_pair(c[prev], c[gt(prev + (1 << j), n)]) !=
            make_pair(c[sc[f][i]], c[gt(sc[f][i] + (1 << j), n)]))
          clas++;
        cc[sc[f][i]] = clas;
        if (j == LOG - 1) p[lst++] = sc[f][i];
        prev = sc[f][i];
      }
      ++clas;
    }
    swap(c, cc);
  }
  return p;
}
vector<string> all;
char chek(string a, string b) {
  for (int j = 0; j < min(a.size(), b.size()); ++j) {
    if (a[j] > b[j]) return 1;
    if (a[j] < b[j]) return 2;
  }
  if (a.size() > b.size()) return 1;
  if (b.size() > a.size()) return 2;
  return 0;
}
vector<int> solve(string t, bool dbg) {
  t += char('a' - 1);
  vector<int> perm = magic(t);
  vector<int> delta(t.size() + 1);
  for (int j = 0; j < all.size(); ++j) {
    int l = 0, r = t.size() - 1;
    while (l != r) {
      int mid = (l + r) >> 1;
      string curr;
      for (int f = perm[mid]; f < min(t.size(), perm[mid] + all[j].size()); ++f)
        curr += t[f];
      if (chek(curr, all[j]) == 1) {
        r = mid;
      } else {
        if (l + 1 == r)
          l = r;
        else
          l = mid;
      }
    }
    if (chek(t.substr(perm[r], min(all[j].size(), t.size() - perm[r])),
             all[j]) == 0)
      ++r;
    int R = r;
    l = 0, r = t.size() - 1;
    while (l != r) {
      int mid = (l + r) >> 1;
      string curr;
      for (int f = perm[mid]; f < min(t.size(), perm[mid] + all[j].size()); ++f)
        curr += t[f];
      if (chek(curr, all[j]) == 2) {
        if (l + 1 == r)
          l = r;
        else
          l = mid;
      } else {
        r = mid;
      }
    }
    if (chek(t.substr(perm[r], min(all[j].size(), t.size() - perm[r])),
             all[j]) == 0) {
      delta[r]++, delta[R]--;
    }
  }
  int curr = 0;
  vector<int> answer(t.size());
  for (int j = 0; j < t.size(); ++j) {
    curr += delta[j];
    answer[perm[j]] = curr;
  }
  return answer;
}
signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  string t;
  int n;
  cin >> t >> n;
  all.resize(n);
  for (int j = 0; j < n; ++j) {
    cin >> all[j];
  }
  vector<int> first = solve(t, 0);
  first.pop_back();
  reverse(t.begin(), t.end());
  for (auto &i : all) reverse(i.begin(), i.end());
  vector<int> second = solve(t, 0);
  second.pop_back();
  reverse(second.begin(), second.end());
  long long ans = 0;
  for (int z = 1; z < t.size(); ++z) {
    ans += 1ll * second[z - 1] * first[z];
  }
  cout << ans;
  return 0;
}

```